array(2) {
["color"]=>
[1]=>
["id"]=> "1"
["name"]=> "Цвет"
["value"]=> "красный"
["photo"]=> "http://google.com/"
[2]=>
["id"]=> "2"
["name"]=> "Цвет"
["value"]=> "зеленый"
["photo"]=> "http://google.com/"
["razmer"]=>
[1]=>
["id"]=> "1"
["name"]=> "Размер"
["value"]=> "900х2000"
["photo"]=> "http://google.com/"
[2]=>
["id"]=> "2"
["name"]=> "Размер"
["value"]=> "800х2000"
["photo"]=> "http://google.com/"
[3]=>
["id"]=> "3"
["name"]=> "Размер"
["value"]=> "700х2000"
["photo"]=> "http://google.com/"
[4]=>
["id"]=> "4"
["name"]=> "Размер"
["value"]=> "600х2000"
["photo"]=> "http://google.com/"
}
<?PHP
$arr =
array("color"=>array(
array(
"id"=> "1",
"name"=> "Цвет",
"value"=> "красный",
"photo"=> "http://google.com/"),
array(
"id"=> "2",
"name"=> "Цвет",
"value"=> "зеленый",
"photo"=> "http://google.com/"
)
),
"razmer"=>array(
array(
"id"=> "1",
"name"=> "Размер",
"value"=> "900х2000",
"photo"=> "http://google.com/"
),
array(
"id"=> "2",
"name"=> "Размер",
"value"=> "800х2000",
"photo"=> "http://google.com/"
),
array(
"id"=> "3",
"name"=> "Размер",
"value"=> "700х2000",
"photo"=> "http://google.com/"
),
array(
"id"=> "4",
"name"=> "Размер",
"value"=> "600х2000",
"photo"=> "http://google.com/"
)
)
);
function getMix($arr,$charr = null,$n = null){
if(!isset($n))
$n = 0;
$tmpArr = array_values($arr);
if(!isset($charr))
$charr = array();
$str = "";
for($i = 0; $i < count($tmpArr[$n]);$i++){
$mycharr = $charr;
array_push($mycharr,$tmpArr[$n][$i]["value"]);
if($n < count($tmpArr)-1)
$str .= getMix($arr,$mycharr,$n+1);
else{
for($j = 0; $j < count($mycharr);$j++)
$str .= $mycharr[$j]." ";
$str .= "<br>";
}
}
return $str;
}
echo getMix($arr);
?>
красный900х2000
красный800х2000
красный700х2000
красный600х2000
зеленый900х2000
зеленый800х2000
зеленый700х2000
зеленый600х2000
foreach($arr as $one){
foreach($one as $item){
echo $item['name'] . ': ' . item['value'];
}
}
foreach($arr['color'] as $item){
echo $item['name'] . ': ' . item['value'];
}
///some code
foreach($arr['someelse'] as $item){
echo $item['name'] . ': ' . item['value'];
}