Array (6=>array (5=> ' Black xx ', 42=> ' XXL '), 7=>array (5=> ' Black xx ', 40=> ' XL '), 8=>array (8=> ' Gray ', 40 + ' XL '),);//Result: Array (0=>array (5=> ' Black xx ', 8=> ' Gray '), 1=>array (42=> ' XXL ', 40=> ' XL '),);
How does the array go horizontally and filter for duplicate values?
Reply to discussion (solution)
$a = Array (6=>array (5=> ' Black xx ', 42=> ' XXL '), 7=>array (5=> ' Black xx ', 40=> ' XL '), 8=>array (8=> ' Gray ', 40=> ' XL '), foreach ($a as $r) { $b [key ($r)] = current ($r); Next ($r); $c [Key ($r)] = current ($r);} $b = Array ($b, $c);p Rint_r ($b);
Array ( [0] = = Array ( [5] = black XX [8] = Ash ) [1] = = Array ([all ] = Xxl
[40] = XL ))
$arr = Array ( 6=>array (5=> ' Black xx ', 42=> ' XXL '), 7=>array (5=> ' Black xx ', 40=> ' XL '), 8=> Array (8=> ' Gray ', 40=> ' XL '), $result = Array (), foreach ($arr as $a) { $keys = Array_keys ($a); $vals = array_values ($a); $result [0][$keys [0]] = $vals [0]; $result [1][$keys [1]] = $vals [1];} Print_r ($result);
Array ( [0] = = Array ( [5] = black XX [8] = Ash ) [1] = = Array ( [42] = > XXL [+] = XL ))
The simplest notation
$a = Array ( 6=>array (5=> ' Black xx ', 42=> ' XXL '), 7=>array (5=> ' Black xx ', 40=> ' XL '), 8=>array (8=> ' grey ', 40=> ' XL '),); foreach ($a as $r) { $i = 0; while (list ($k, $v) = each ($r)) $b [$i ++][$k] = $v;} Print_r ($b);
Array ( [0] = = Array ( [5] = black XX [8] = Ash ) [1] = = Array ([all ] = XXL [+] = XL ))
The simplest notation
$a = Array ( 6=>array (5=> ' Black xx ', 42=> ' XXL '), 7=>array (5=> ' Black xx ', 40=> ' XL '), 8=> Array (8=> ' Gray ', 40=> ' XL '),); foreach ($a as $r) { $i = 0; while (list ($k, $v) = each ($r)) $b [$i ++][$k] = $v;} Print_r ($b);
Array ( [0] = = Array ( [5] = black XX [8] = Ash ) [1] = = Array ([all ] = Xxl
[40] = XL ))
This method is good!!!