Compare the keys and values of two arrays (using a built-in function to compare the keys and a user-defined function to compare


SUBMITTED BY: henry1874w

DATE: June 26, 2017, 4:49 p.m.

FORMAT: Text only

SIZE: 275 Bytes

HITS: 277

  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"=>"blue","c"=>"green");
  12. $result=array_udiff_assoc($a1,$a2,"myfunction");
  13. print_r($result);
  14. ?>

comments powered by Disqus