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


SUBMITTED BY: henry1874w

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

FORMAT: Text only

SIZE: 279 Bytes

HITS: 237

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

comments powered by Disqus