PHP combines a two-dimensional array with the same array of fields, a two-dimensional array of arrays
This example describes how PHP merges the same array of one field in a two-dimensional array. Share to everyone for your reference, as follows:
Example:
Array (3) {[0]=> Array (+) {["id"]=> string (2) "56" ["UID"]=> string (2) "+" ["Euid"]=> string (2) ["Did"]=> string (1) "1" ["Nid"]=> string (1) "0" ["Phonetime"]=> string (Ten) "1443927600" ["Createtime"]=> ; String (Ten) "1443880619" ["Type"]=> string (1) "3" ["Status"]=> string (1) "0" ["Atype"]=> string (1) "1" ["MT Ype "]=> string (1)" 2 "[" Endtime "]=> string (1)" 0 "[" Time "]=> string (10)" October 04 "[" Date "]=> string (6)" Sunday "[" uname "]=> NULL [" album "]=> string (0)" "} [1]=> Array (+) {[" id "]=> string (2)" "[" UID "]=> String (2) "+" ["Euid"]=> string (2) "1" ["Did"]=> string (1) "1" ["Nid"]=> string (0) "" ["Phonetime"]=&G T String "1444359600" ["Createtime"]=> string "1444268595" ["Type"]=> string (1) "3" ["Status"]=> stri Ng (1) "0" ["Atype"]=> string (1) "1" ["Mtype"]=> string (1) "2" ["Endtime"]=> string (1) "0" ["Time"]=> s Tring (10) "October 09"[" Date "]=> string (6)" Friday "[" uname "]=> NULL [" album "]=> string (0)" "} [2]=> Array (+) {[" id "]=> String (2) "]=>" ["UID") string (1) "2" ["Euid"]=> string (2) "1" ["Did"]=> string (1) "" ["Nid"]=> str ING (1) "0" ["Phonetime"]=> string (Ten) "1444359620" ["Createtime"]=> string "1444268595" ["Type"]=> stri Ng (1) "3" ["Status"]=> string (1) "0" ["Atype"]=> string (1) "1" ["Mtype"]=> string (1) "2" ["Endtime"]=> String (1) "0" ["Time"]=> string (10) "October 09" ["Date"]=> string (6) "Friday" ["uname"]=> NULL ["album"]=> s Tring (0) ""}}
The
now wants to merge the elements under this two-dimensional array into the same array as time. The desired effect is:
Array (2) {["October 04"]=> Array (1) {[0]=> Array (+) {["id"]=> string (2) "" "[" UID "]=> string (2)" 14 "[" Euid "]=> string (2)" "" "[" Did "]=> string (1)" 1 "[" Nid "]=> string (1)" 0 "[" Phonetime "]=> St Ring "1443927600" ["Createtime"]=> string (Ten) "1443880619" ["Type"]=> string (1) "3" ["Status"]=> String (1) "0" ["Atype"]=> string (1) "1" ["Mtype"]=> string (1) "2" ["Endtime"]=> string (1) "0" ["Tim E "]=> string (10)" October 04 "[" Date "]=> string (6)" Sunday "[" uname "]=> NULL [" album "]=> string (0)"} } ["October 09"]=> Array (2) {[0]=> Array (+) {["id"]=> string (2) "" ["UID"]=> string (2) "[" EU ID "]=> string (2)" "]=>" ["Did" string (1) "1" ["Nid"]=> string (1) "0" ["Phonetime"]=> string (10) "1444359600" ["Createtime"]=> string (Ten) "1444268595" ["Type"]=> string (1) "3" ["Status"]=> string (1 ) "0" ["Atype"]=> String (1) "1" ["Mtype"]=> string (1) "2" ["Endtime"]=> string (1) "0" ["Time"]=> string (10) "October 09" ["Date"]=> string (6) "Friday" ["uname"]=> NULL ["album"]=> string (0) ""} [1]=> Array (+) {["id"] = = String (2) "" "[" UID "]=> string (1)" 2 "[" Euid "]=> string (2)" 1 "[" Did "]=> string (1)" [" Nid "]=> string (1)" 0 "[" Phonetime "]=> string (Ten)" 1444359620 "[" Createtime "]=> string (10)" 1444268595 " ["Type"]=> string (1) "3" ["Status"]=> string (1) "0" ["Atype"]=> string (1) "1" ["Mtype"]=> stri Ng (1) "2" ["Endtime"]=> string (1) "0" ["Time"]=> string (10) "October 09" ["Date"]=> string (6) "Friday" ["UN Ame "]=> NULL [" album "]=> string (0)" "}}}
So... The code is simple, not as complex as it is imagined, and the desired result is a three-dimensional array
$result as the original two-dimensional array
$res = Array (); Desired result foreach ($result as $k = = $v) { $res [$v [' time ']][] = $v;}
More readers interested in PHP related content can view the topic: "PHP Primer for Object-oriented programming", "PHP String Usage Summary", "Php+mysql Database Operations Primer" and "PHP common database Operation Skills Summary"
I hope this article is helpful to you in PHP programming.
Articles you may be interested in:
- PHP two-dimensional array merging and de-duplication method
- Simple implementation method of PHP two-dimensional array sorting
- Php method for sorting two-dimensional arrays by specified key values
- Two types of PHP to remove a two-dimensional array of repeating Item method
- A method for removing duplicates of two-dimensional arrays by PHP
- A detailed approach to the problem of two-dimensional array sorting in PHP
- A method of implementing one-dimensional array to two-dimensional array in PHP
- PHP number combination and analysis with split instance
- Improvements to merge arrays in PHP with the same key values for a field
- Two ways to merge PHP arrays
- Two methods and differences of array merging in PHP
http://www.bkjia.com/PHPjc/1104335.html www.bkjia.com true http://www.bkjia.com/PHPjc/1104335.html techarticle PHP combines a two-dimensional array with the same array of fields, a two-dimensional array of arrays This example describes the method by which PHP merges the same array of one field in a two-dimensional array. ...