3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function permute($base, $add) { $result = []; if (count($base) > 0) { foreach ($base as $val1) { if (count($add) > 0) { foreach ($add as $val2) { $result[] = array_merge($val1, $val2); } } else { $result = $base; } } } else { $result = $add; } return $result; } function getPermutations(array $optionSet) { $stuff = []; $permutations = []; $index = 0; foreach ($optionSet as $key => $set) { $stuff[$index] = []; foreach ($set as $code => $name) { array_push($stuff[$index], [$key => $code]); } $index++; } $count = count($stuff); for ($i = 0; $i < $count; $i++) { $temp = array_map( [ $this, "permute", ], [$permutations], [$stuff[$i]] ); $permutations = $temp[0]; } return $permutations; } $options = [ 'Condition' => [ 'nm' => 'Near Mint/Mint', 'sp' => 'Slightly Played', 'hp' => 'Heavily Played' ], 'Style' => [ 'normal' => 'Normal', 'foil' => 'Foil' ] ]; var_dump(getPermutations($options));
Output for 7.1.0 - 7.2.0
Fatal error: Uncaught Error: Using $this when not in object context in /in/kiqj2:40 Stack trace: #0 /in/kiqj2(67): getPermutations(Array) #1 {main} thrown in /in/kiqj2 on line 40
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Notice: Undefined variable: this in /in/kiqj2 on line 40 Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /in/kiqj2 on line 44 Notice: Undefined variable: this in /in/kiqj2 on line 40 Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /in/kiqj2 on line 44 NULL
Output for 5.4.12 - 5.6.28
Notice: Undefined variable: this in /in/kiqj2 on line 40 Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /in/kiqj2 on line 45 Notice: Undefined variable: this in /in/kiqj2 on line 40 Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /in/kiqj2 on line 45 NULL
Output for 5.3.22 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/kiqj2 on line 5
Process exited with code 255.