PHP array operation problems include two arrays $ a and $ B.
$ A = array ("1" => "123", "2" => "1234", "3" => "1334 ");
$ B = array ("1" => "123," 2 "=>" 1230 ");
How do I get $ c = array ("2" => "12234", "3" => "delete ");
Because the 123 values corresponding to 1 are the same, the 2 values are removed. because $ B is smaller than $ a, the 3 values of $ a must be retained. because it does not exist, it is followed by "delete".
Reply to discussion (solution)
$ A = array ("1" => "123", "2" => "1234", "3" => "1334 "); $ B = array ("1" => "123", "2" => "1230"); $ c = array (); foreach ($ a as $ k =>$ v) {if (isset ($ B [$ k]) {if ($ B [$ k] ==$ v) continue; // save the same $ c [$ k] = max ($ B [$ k], $ v ); // The else $ c [$ k] = 'delete';} print_r ($ c );Array
(
[2] => 1234.
[3] => delete
)
$a = array("1"=>"123","2"=>"1234","3"=>"1334");$b = array("1"=>"123","2"=>"1230");$c = array();foreach($a as $key=>$val){if(isset($b[$key])){if($val!=$b[$key]){$c[$key] = $val>$b[$key]? $val : $b[$key];}}else{$c[$key] = 'delete';}}print_r($c);