Re: compare values in 2 array

From: Date: Fri, 28 Jul 2006 11:02:18 +0000
Subject: Re: compare values in 2 array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-239850@lists.php.net to get a copy of this message
On 7/28/06, weetat <weetat.yeo@cxrus.com> wrote:
I need to compare values in array which populated by database , below is the code :
Without mentioning how your code performs some unnecessary actions, and is also full of errors, here's the idea of what you want (untested): [code] // assume at first they are same $compare = true; // compare $array1 and $array2, assuming they have same structure foreach($array1 as $key => $val) { // value doesn't match, so set $compare to false and break out of for loop if($array2[$key] != $val) {
       $compare = false;
       break;
} } if($compare === false) { echo 'arrays did not match.'; } [/code] HTH, John W

« previous php.general (#239850) next »