This article mainly introduces the implementation of PHP array based on a key value to merge the same key values to generate a new two-dimensional array, involving the traversal of the PHP array, assignment-related arithmetic skills, the need for friends can refer to the next
The example in this paper describes a method by which the PHP array implements a new two-dimensional array that merges the same key values according to a key value. Share to everyone for your reference, as follows:
Source data:
$infos = Array (' a ' = = ', ' b ' = = ' xa ', ' c ' = ' 2015-08-28 00:00:00 ', ' d ' = ' = ' 2015/08/4384 88a00b3219929282e3652061c2e3.png '), Array (' a ' = = 3, ' b ' = ' VD ', ' c ' = ' = ' 2015-08-20 00:00:00 ', ' d ' = = ' 2015/08/438488a00b3219929282e3652061c2e3.png '), Array (' a ' = = 6, ' b ' = ' wwe ', ' c ' = ' + ' 2015- 08-28 00:00:00 ', ' d ' = ' 2015/08/438488a00b3219929282e3652061c2e3.png '), Array (' a ' = = ', ' b ' = = ' SE ', ' c ' = ' 2015-08-28 00:00:00 ', ' d ' = ' 2015/08/438488a00b3219929282e3652061c2e3.png '), Array (' a ' => ; 6, ' b ' = ' aw ', ' c ' = ' 2015-08-28 00:00:00 ', ' d ' = ' 2015/08/438488a00b3219929282e3652061c2e3.png '), Array (' a ' = =, ' b ' = ' bv ', ' c ' = ' 2015-08-28 00:00:00 ', ' d ' and ' = ' 2015/08/438488a00b3219929282 E3652061c2e3.png '), Array (' a ' = = ', ' b ' = = ' xx ', ' c ' = ' = ' 2015-08-27 00:00:00 ', ' d ' and ' = ' 2015/0 8/438488a00b3219929282E3652061c2e3.png '));
Processing requirements: Merges the same two-dimensional array of a in an array into an array, creating a new array
Code:
<?php $result = Array (); foreach ($infos as $key = + $info) { $result [$info [' a ']][] = $info;} print_r ($result);
Output:
Array ([+] = = Array ([0] = = Array ([a] = [b] = = XA [c] = = 2015-08-28 00:00:00 [d] = = 2015/08/438488a00b3219929282e3652061c2e3.png) [1] = = Array ([a] = [b] = + se [ c] = 2015-08-28 00:00:00 [d] = 2015/08/438488a00b3219929282e3652061c2e3.png) [2] = = Array ([a ] = [b] = BV [c] = 2015-08-28 00:00:00 [d] = 2015/08/438488a00b3219929282e3652061c2e3.png )) [3] = = Array ([0] = = Array ([a] = 3 [b] = VD [c] = = 2015-08-20 00:00:00 [d ] = = 2015/08/438488a00b3219929282e3652061c2e3.png)) [6] = = Array ([0] = = Array ([A] = 6 [b] = WWE [c] = 2015-08-28 00:00:00 [d] = 2015/08/438488a00b3219929282e3652061c2e3.png) [1] =&G T Array ([A] = 6 [b] = AW [c] = 2015-08-28 00:00:00 [d] = 2015/08/438488a00b3219929282e3 652061c2e3.png)) = = Array ([0] = = Array ([a] = [b] = + xx [c] = = 2015-08-27 00:00:00 [d] = > 2015/08/438488a00b3219929282e3652061c2e3.png)))
The above is the whole content of this article, I hope that everyone's study has helped.