3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getCombinations(...$arrays) { $result = [[]]; foreach ($arrays as $property => $property_values) { $tmp = []; foreach ($result as $result_item) { foreach ($property_values as $property_value) { $tmp[] = array_merge($result_item, [$property => $property_value]); } } $result = $tmp; } return $result; } $atrs_ref = ['p', 'm', 'g']; $colors=['blanco', 'negro', 'rojo']; $sizes=['corta', 'larga'] ; print_r(getCombinations($atrs_ref, $colors, $sizes));
Output for git.master_jit, git.master
Array ( [0] => Array ( [0] => p [1] => blanco [2] => corta ) [1] => Array ( [0] => p [1] => blanco [2] => larga ) [2] => Array ( [0] => p [1] => negro [2] => corta ) [3] => Array ( [0] => p [1] => negro [2] => larga ) [4] => Array ( [0] => p [1] => rojo [2] => corta ) [5] => Array ( [0] => p [1] => rojo [2] => larga ) [6] => Array ( [0] => m [1] => blanco [2] => corta ) [7] => Array ( [0] => m [1] => blanco [2] => larga ) [8] => Array ( [0] => m [1] => negro [2] => corta ) [9] => Array ( [0] => m [1] => negro [2] => larga ) [10] => Array ( [0] => m [1] => rojo [2] => corta ) [11] => Array ( [0] => m [1] => rojo [2] => larga ) [12] => Array ( [0] => g [1] => blanco [2] => corta ) [13] => Array ( [0] => g [1] => blanco [2] => larga ) [14] => Array ( [0] => g [1] => negro [2] => corta ) [15] => Array ( [0] => g [1] => negro [2] => larga ) [16] => Array ( [0] => g [1] => rojo [2] => corta ) [17] => Array ( [0] => g [1] => rojo [2] => larga ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
53.04 ms | 411 KiB | 5 Q