3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $var = [ 'TSHIRT' => [ 'farbe' => [ 'blau', 'rot' ], 'groesse' => [ '10cm' ], 'breite' => [ '5cm' ] ] ]; $result = array(); $tmp = array(); foreach ($var as $articleKey => $articleVal) { $merkmalKeys = array_keys($articleVal); foreach ($articleVal as $merkmalKey=>$merkmalValue) { foreach($articleVal as $merkmalKey2=>$merkmalValue2) { if($merkmalKey2 == $merkmalKey) { continue; } foreach($merkmalValue as $b) { foreach($merkmalValue2 as $a) { $tmp[] = $articleKey . ' - ' . $b . ' / ' . $a; } } var_dump($merkmalValue2); } } } var_dump($tmp);
based on BhQZo
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0rc3
array(1) { [0]=> string(4) "10cm" } array(1) { [0]=> string(3) "5cm" } array(2) { [0]=> string(4) "blau" [1]=> string(3) "rot" } array(1) { [0]=> string(3) "5cm" } array(2) { [0]=> string(4) "blau" [1]=> string(3) "rot" } array(1) { [0]=> string(4) "10cm" } array(10) { [0]=> string(20) "TSHIRT - blau / 10cm" [1]=> string(19) "TSHIRT - rot / 10cm" [2]=> string(19) "TSHIRT - blau / 5cm" [3]=> string(18) "TSHIRT - rot / 5cm" [4]=> string(20) "TSHIRT - 10cm / blau" [5]=> string(19) "TSHIRT - 10cm / rot" [6]=> string(19) "TSHIRT - 10cm / 5cm" [7]=> string(19) "TSHIRT - 5cm / blau" [8]=> string(18) "TSHIRT - 5cm / rot" [9]=> string(19) "TSHIRT - 5cm / 10cm" }