Wednesday, July 18, 2012

Compare two array has equal values


for eg;
$restids = array("apple","mango");
$asvals = array("apple","mango");

You can't get the results for equal array check with array_diff function if the second array dynamically changes

You can do on thing for this

if(count(array_diff($restids,$asvals)) == 0 && count(array_diff($asvals,$restids)) == 0){
    return true;
}

This condition will get you the if two array has equal values or not.

No comments:

Post a Comment