3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $products = [1, 2, 3, 4, 5]; $vendors = ["Amazon", "Newegg", "##php"]; $combinations = []; foreach ($vendors as $vendor) { foreach ($products as $productID) { $combinations[] = array('product' => $productID, 'vendor' => $vendor); } } var_dump($combinations);
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(15) { [0]=> array(2) { ["product"]=> int(1) ["vendor"]=> string(6) "Amazon" } [1]=> array(2) { ["product"]=> int(2) ["vendor"]=> string(6) "Amazon" } [2]=> array(2) { ["product"]=> int(3) ["vendor"]=> string(6) "Amazon" } [3]=> array(2) { ["product"]=> int(4) ["vendor"]=> string(6) "Amazon" } [4]=> array(2) { ["product"]=> int(5) ["vendor"]=> string(6) "Amazon" } [5]=> array(2) { ["product"]=> int(1) ["vendor"]=> string(6) "Newegg" } [6]=> array(2) { ["product"]=> int(2) ["vendor"]=> string(6) "Newegg" } [7]=> array(2) { ["product"]=> int(3) ["vendor"]=> string(6) "Newegg" } [8]=> array(2) { ["product"]=> int(4) ["vendor"]=> string(6) "Newegg" } [9]=> array(2) { ["product"]=> int(5) ["vendor"]=> string(6) "Newegg" } [10]=> array(2) { ["product"]=> int(1) ["vendor"]=> string(5) "##php" } [11]=> array(2) { ["product"]=> int(2) ["vendor"]=> string(5) "##php" } [12]=> array(2) { ["product"]=> int(3) ["vendor"]=> string(5) "##php" } [13]=> array(2) { ["product"]=> int(4) ["vendor"]=> string(5) "##php" } [14]=> array(2) { ["product"]=> int(5) ["vendor"]=> string(5) "##php" } }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/RAM25 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/RAM25 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/RAM25 on line 3
Process exited with code 255.