Compare the keys and values of three arrays (use a user-defined function to compare the keys), and return the matches:


SUBMITTED BY: henry1874w

DATE: June 23, 2017, 9:35 p.m.

FORMAT: Text only

SIZE: 334 Bytes

HITS: 236

  1. <?php
  2. function myfunction($a,$b)
  3. {
  4. if ($a===$b)
  5. {
  6. return 0;
  7. }
  8. return ($a>$b)?1:-1;
  9. }
  10. $a1=array("a"=>"red","b"=>"green","c"=>"blue");
  11. $a2=array("a"=>"red","b"=>"green","d"=>"blue");
  12. $a3=array("e"=>"yellow","a"=>"red","d"=>"blue");
  13. $result=array_intersect_uassoc($a1,$a2,$a3,"myfunction");
  14. print_r($result);
  15. ?>

comments powered by Disqus