Compare the keys and values of two arrays, and return the matches (using a user-defined key comparison function):


SUBMITTED BY: henry1874w

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

FORMAT: Text only

SIZE: 280 Bytes

HITS: 248

  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("d"=>"red","b"=>"green","e"=>"blue");
  12. $result=array_intersect_uassoc($a1,$a2,"myfunction");
  13. print_r($result);
  14. ?>

comments powered by Disqus