简体   繁体   中英

Compare Two Associative Array with different value

I have two Associative array.

$a1 = array("Peter"=>"a","Ben"=>"b","Joe"=>"c");
$a2 = array("Peter"=>"5","Joe"=>"15");

and Out put result should be...

a=5
b=null
c=15
foreach($a1 as $aKey => $aValue) {
    echo $aValue, '=';
    echo (isset($a2[$aKey])) ? $a2[$aKey] : 'null';
    echo PHP_EOL;
}
foreach($a1 as $key => $value) {
    echo $a1[$key].'='.$a2[$key];
}

You will get the output, but this have nothing to do with array comparing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM