Say that I have an array like the following:
Array ( [arm] => Array ( [0] => A [1] => B [2] => C
In PHP 7 @Serg's answer can be shortened to:
function cartesian(array $input) { $result = [[]]; foreach ($input as $key => $values) { $append = []; foreach ($values as $value) { foreach ($result as $data) { $append[] = $data + [$key => $value]; } } $result = $append; } return $result; }