PHP array operation problems include two arrays $ a and $ B $ aarray (1 & gt; 123,2 & gt; 1234,3 & gt; 1334); $ barray (1 & gt; 1230, 2 & gt; 123); how to get $ carray (2 & gt; 12234,3 & gt; "delete); because the & nbsp; corresponding to 1 is a PHP array operation problem
For example, there are 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".
------ Solution --------------------
$ 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 );