3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $products = [1, 2, 3, 4, 5]; $vendors = ["Amazon", "Newegg", "Frys"]; $product_combinations = array(); $vendor_combinations = array(); function pc_permute($items, &$combinations, $perms = array()) { if (empty($items)) { $combinations[] = $perms; } else { for ($i = count($items) - 1; $i >= 0; --$i) { $newitems = $items; $newperms = $perms; list($foo) = array_splice($newitems, $i, 1); array_unshift($newperms, $foo); pc_permute($newitems, $combinations, $newperms); } } } // Build product combinations //pc_permute($products, $product_combinations); // Build vendor combinations pc_permute($vendors, $vendor_combinations); var_dump($vendor_combinations);
Output for 5.4.0 - 7.1.0
array(6) { [0]=> array(3) { [0]=> string(6) "Amazon" [1]=> string(6) "Newegg" [2]=> string(4) "Frys" } [1]=> array(3) { [0]=> string(6) "Newegg" [1]=> string(6) "Amazon" [2]=> string(4) "Frys" } [2]=> array(3) { [0]=> string(6) "Amazon" [1]=> string(4) "Frys" [2]=> string(6) "Newegg" } [3]=> array(3) { [0]=> string(4) "Frys" [1]=> string(6) "Amazon" [2]=> string(6) "Newegg" } [4]=> array(3) { [0]=> string(6) "Newegg" [1]=> string(4) "Frys" [2]=> string(6) "Amazon" } [5]=> array(3) { [0]=> string(4) "Frys" [1]=> string(6) "Newegg" [2]=> string(6) "Amazon" } }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/I4P06 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/I4P06 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/I4P06 on line 3
Process exited with code 255.