Toggle navigation
Home
Latest pastes
FAQ
Random
Register
Login
Compare the keys and values of two arrays (using two user-defined functions for comparison) and return the differences:
SUBMITTED BY:
henry1874w
DATE:
June 26, 2017, 4:51 p.m.
FORMAT:
Text only
SIZE:
407 Bytes
Raw
Download
Tweet
HITS:
232
Go to comments
Report
<?php
function myfunction_key($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
function myfunction_value($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"red","b"=>"green","c"=>"green");
$result=array_udiff_uassoc($a1,$a2,"myfunction_key","myfunction_value");
print_r($result);
?>
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus