how does array_diff work?
Posted
by SpawnCxy
on Stack Overflow
See other posts from Stack Overflow
or by SpawnCxy
Published on 2010-03-19T19:11:23Z
Indexed on
2010/03/19
19:21 UTC
Read the original article
Hit count: 125
I just wonder how array_diff()
works.And obviously it couldn't work as follows
function array_diff($arraya, $arrayb)
{
$diffs = array();
foreach ($arraya as $keya => $valuea)
{
foreach ($arrayb as $valueb)
{
if ($valuea == $valueb)
{
break;
}
$diffs[$keya]=$valuea;
}
}
return $diffs;
} //couldn't be worse than this
Hope someone can show me some better solution.
Thanks.
© Stack Overflow or respective owner