fork download
  1. <?php
  2.  
  3. $bio= "Tom, male, spain";
  4.  
  5. $list = array(
  6. 1 => array("Tom", "male", "UK"),
  7. 8 => array("bob", "Male", "spain"),
  8. 4 => array("Tom", "male", "spain"),
  9. 9 => array("sam", "femail", "United States")
  10. );
  11.  
  12. #print_r($list);
  13.  
  14. $percent_old = 0;
  15. foreach ($list as $key => $value ) # loop the arrays
  16. {
  17. $text = implode(", ", $value); # implode the arrays to get a string similar to $bio
  18. similar_text($bio, $text, $percent); # get a percentage of similar text
  19.  
  20. if ($percent > $percent_old) # check if the current value of $percent is > to the old one
  21. {
  22. $percent_old = $percent; # assign $percent to $percent_old
  23. $final_result = $key; # assign $key to the value of $final_result
  24. }
  25. }
  26.  
  27. print $final_result;
  28.  
Success #stdin #stdout 0s 83456KB
stdin
Standard input is empty
stdout
4