fork download
  1. <?php
  2. $arr = array(
  3. 501=>"a",
  4. 402=>"b",
  5. 303=>"c",
  6. 204=>"d",
  7. 105=>"a",
  8. );
  9. /*
  10. http://w...content-available-to-author-only...p.net/manual/en/function.array-flip.php
  11. array_flip:
  12. array_flip() returns an array in flip order,
  13. i.e. keys from trans become values
  14. and values from trans become keys.
  15.  
  16. If a value has several occurrences,
  17. the latest key will be used as its values,
  18. and all others will be lost.
  19. */
  20. foreach ($arr as $key1 => $value1) {
  21. /* 空の配列はFALSEなので注意 */
  22. if(array_search($key1,$arr2,true) === FALSE){
  23. continue;
  24. }
  25.  
  26. foreach ($arr as $key2 => $value2) {
  27. if($value1 !== $value2 || $key1 == $key2 ){
  28. continue;
  29. }
  30. print_r("dupe:" . $key2 . ":" . $value2 . "\n");
  31. }
  32. }
  33. ?>
Success #stdin #stdout 0.01s 13112KB
stdin
Standard input is empty
stdout
dupe:105:a