Re: compare values in 2 array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/28/06, weetat <weetat.yeo@xxxxxxxxx> 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux