array( array( "ShopID" => "C024", "Name" => "a", "ListNo" => 13343 ), array( "ShopID" => "C024", "Name" => "c", "ListNo" => 13343 ), array( "ShopID" => "C024", "Name" => "b", "ListNo" => 13342 ), array( "ShopID" => "C024", "Name" => "d", "ListNo" => 13342 ), array( "ShopID" => "C024", "Name" => "e", "ListNo" => 13346 ), array( "ShopID" => "C024", "Name" => "f", "ListNo" => 13346 ));
Listno the same values to reorganize into an array, the effect of the implementation:
array("ShopID" => "C024", "Name" => array("a", "c"), "ListNo" = 13343);
Reply content:
array( array( "ShopID" => "C024", "Name" => "a", "ListNo" => 13343 ), array( "ShopID" => "C024", "Name" => "c", "ListNo" => 13343 ), array( "ShopID" => "C024", "Name" => "b", "ListNo" => 13342 ), array( "ShopID" => "C024", "Name" => "d", "ListNo" => 13342 ), array( "ShopID" => "C024", "Name" => "e", "ListNo" => 13346 ), array( "ShopID" => "C024", "Name" => "f", "ListNo" => 13346 ));
Listno the same values to reorganize into an array, the effect of the implementation:
array("ShopID" => "C024", "Name" => array("a", "c"), "ListNo" = 13343);
$arr = Array ("Shopid" = "C024", "Name" = "a", "listno" = 13343), Array ("shopid" = "C024", "Name" = "C", "Listno" and "=" 13343), Array ("shopid" = "C024", "Name" = "B", "Listno" = 1 3342), Array ("shopid" = "C024", "Name" = "D", "Listno" and "= 13" 342), Array ("shopid" = "C024", "Name" = "E", "listno" = 133 , Array ("shopid" = "C024", "Name" = "F", "listno" = 1334 6)); $lists = Array_column ($arr, ' Listno '); $lists = Array_flip (Array_flip ($lists)); $result = Array (); foreach ($lists as $k = = $v) {$res = array (); foreach ($arr as $key = + $val) {if ($val [' listno '] = = $v) { if (count ($res) = = 0) {$res = $val; } else {if ($res [' shopid ']! = $val [' shopid ']) {if (!is_array ($res [' shopid '])) {$res [' shopid '] = Array ($res [' shopid '], $val [' shopid ']); } else {$res [' shopid '] [] = $val [' Shopid ']; }} if ($res [' name ']! = $val [' name ']) {if (!is_array ($res [' N Ame ']) {$res [' name '] = Array ($res [' name '], $val [' name ']); } else {$res [' name '] [] = $val [' name ']; }}}}//Var_dump ($res); } $result [] = $res; } var_dump ($result);
结果如下:array (size=3)
0 =
array (size=3) 'ShopID' => string 'C024' (length=4) 'Name' => array (size=2) 0 => string 'a' (length=1) 1 => string 'c' (length=1) 'ListNo' => int 13343
1 =
array (size=3) 'ShopID' => string 'C024' (length=4) 'Name' => array (size=2) 0 => string 'b' (length=1) 1 => string 'd' (length=1) 'ListNo' => int 13342
2 =
array (size=3) 'ShopID' => array (size=2) 0 => string 'C024' (length=4) 1 => string 'C025' (length=4) 'Name' => array (size=3) 0 => string 'e' (length=1) 1 => string 'f' (length=1) 2 => string 'g' (length=1) 'ListNo' => int 13346
Traversing the array, traversing the Listno as key, and then judged if isset the same key to the name of the merge operation, not directly written to the last array_merge to clear the array of key