In PHP, two-dimensional array replacement problem A array: $ dbData = array (& nbsp; array (0, 'zhangsan', 'hangzhou'), & nbsp; array (1, 'Lee 4', 'Taobao'), & nbsp; array (2, 'two', 'two-dimensional array replacement in PHP
Array:
$ DbData = array (
Array (0, 'Zhang San', 'Dinner '),
Array (1, 'Li Si', 'Dinner '),
Array (2, 'two', 'hangzhou '),
Array (3, 'two', 'drinking water ')
);
B array
$ ExcelData = array (
Array (0, 'zhangsan', 'zhangsan '),
Array (1, 'lisi', 'Li si '),
Array (2, 'mazi', 'machin ')
);
To replace the elements in array A with array B, Michael Jacob uses zhangsan instead of lisi, and Ma zi uses mazi instead.
The following result is obtained:
C array:
$ DbData = array (
Array (0, 'hangsan ', 'hangzhou '),
Array (1, 'lisi', 'hangzhou '),
Array (2, 'mazi', 'hangzhou '),
Array (3, 'mazi', 'Shanghai ')
);
------ Solution --------------------
PHP code
$ DbData = array (0, 'Taobao', 'Taobao'), array (1, 'Li Si', 'Taobao'), array (2, 'machin ', 'hangzhou'), array (3, 'two', 'hangzhou'); $ excelData = array (0, 'hangsan', 'zhangsan '), array (1, 'lisi', 'Li si'), array (2, 'mazi', 'ma Zi'); // transform $ excelData because it is the replacement subject, therefore, the key-value pair must be a unique foreach ($ excelData as $ v) $ dict [$ v [2] = $ v; // start to replace foreach ($ dbData as & $ v) $ v [1] = $ dict [$ v [1] [1]; // check the result print_r ($ dbData );