The example in this article describes the way in which PHP merges the same array of one field in a two-dimensional array. Share to everyone for your reference, specific as follows:
Example:
Array (3) {[0]=> array {["id"]=> string (2) "" ["UID"]=> string (2) "" ["Euid"]=> string (2) ["Did"]=> string (1) "1" ["Nid"]=> string (1) "0" ["Phonetime"]=> string (10) "1443927600" [] Createtime "]=> string" 1443880619 ["type"]=> string (1) "3" ["Status"]=> string (1) "0" ["Atype"]= > string (1) "1" ["Mtype"]=> string (1) "2" ["Endtime"]=> string (1) "0" ["Time"]=> string (10)] October
04th "[Date"]=> string (6) "Sunday" ["uname"]=> NULL ["album"]=> string (0) ""} [1]=> Array (16) { [ID]=> string (2) ' [' UID ']=> string (2) ' [' Euid ']=> string (2) ' [' Did ']=> string (1) '] 1 "[Nid"]=> string (1) "0" ["Phonetime"]=> string (a) "1444359600" ["Createtime"]=> string (10) "14442"
68595 ' [' 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) ""} [2]=> array {["id"]=> string (2) "" ["UID"]=> string (1) "2" ["Euid"]=> string (2) "1" ["Did"]=> string () "1" ["Nid"]=> string (1) "0" ["Phonetime"]=> Strin G (a) "1444359620" ["Createtime"]=> string (a) "1444268595" ["Type"]=> string (1) "3" ["Status"]=> str ING (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) ""}}
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"]=> stri Ng (2) "1" ["Euid"]=> string (2) "A" ["Did"]=> string () "1" ["Nid"]=> string (1) "0" ["Phone
Time "]=> string" 1443927600 ["Createtime"]=> string (a) "1443880619" ["Type"]=> string (1) "3" ["Status"]=> string (1) "0" ["Atype"]=> string (1) "1" ["Mtype"]=> string (1) "2" ["Endtime"]=
> string (1) "0" ["Time"]=> 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) "[Euid"]=> string (2) "" ["Did"]=> string (1) "1" ["Nid"]=&G
T String (1) "0" ["Phonetime"]=> string (a) "1444359600" ["Createtime"]=> string (a) "1444268595" ["Type "]=> String (1 "3" ["Status"]=> string (1) "0" ["Atype"]=> string (1) "1" ["Mtype"]=> string (1) "2" ["Endt
IME "]=> 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) "" ["Did"]=> string (1) "1" ["Nid"]=> string (1) "0" ["ph Onetime "]=> string" 1444359620 ["Createtime"]=> string (a) "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 "]=> N
ull ["album"]=> string (0) ""}}}
So... The code is simple, not as complex as it might seem, and the desired result is a three-dimensional array
$result is the original two-dimensional array
$res = Array (); Desired result
foreach ($result as $k => $v) {
$res [$v [' time ']][] = $v;
}
For more information about PHP interested readers can view the site topics: "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP Common database Operation tips Summary"
I hope this article will help you with the PHP program design.