3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isEmptyArray($item) { if (is_array($item)) { return array_filter($item, 'isEmptyArray'); } if (!empty($item) || $item === "0") { return true; } return false; } function removeEmptyArrays($array) { $filteredArray = array_filter($array, 'isEmptyArray'); return $filteredArray; } function isMultiDimensional($array) { if(is_array($array)) { foreach ($array as $key=>$value){ if(is_array($value)){ return true; } } } return false; } $str='discount_rule[0][service_no][0][service_nos]=100';//'service[0][tier][0][schedule][0][amount]=10'; parse_str($str, $output); $cat='admintools-api'; $options = array(); $apiLiveOptions = array(); foreach ($output AS $key => $value) { if (is_array($value)) { if (!empty($value[$key])) { $options[$key] = $value; $apiLiveOptions[$key] = $value; } else { $array = array(); $apiLiveArray = array(); foreach ($value as $k => $v) { if(!empty($v[$k])) { $array[] = $value[$k]; $apiLiveArray[] = $value[$k]; $options[$key] = $array; } else { $newArray = array_filter($v, 'isEmptyArray'); $apiLiveArray[$k] = $newArray; foreach($newArray as $row => $column) { if(is_array($column)) { foreach($column as $r=>$c) { if($cat=='admintools-api') { var_dump($c); var_dump(count(array_values($c)[0])); //$options[$key][$k][$row][$r]=array_values($c)[0]; } else { $options[$row][$r]=$c; } } } else { if($cat=='admintools-api') { $key == $row ? $options[$key][$k] = $column : $options[$key][$k][$row] = $column; } else { $array[$k]=$column; $options[$row] = $array; } } } } } $apiLiveOptions[$key] = $apiLiveArray; } } else { $options[$key] = $value; $apiLiveOptions[$key] = $value; } }; //var_dump($apiLiveOptions); ?>
Output for 8.0.10 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
array(1) { ["service_nos"]=> string(3) "100" } Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in /in/slG4O:58 Stack trace: #0 {main} thrown in /in/slG4O on line 58
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 array(1) { ["service_nos"]=> string(3) "100" } Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in /in/slG4O:58 Stack trace: #0 {main} thrown in /in/slG4O on line 58
Process exited with code 255.
Output for 8.0.0 - 8.0.9
array(1) { ["service_nos"]=> string(3) "100" } Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, string given in /in/slG4O:58 Stack trace: #0 {main} thrown in /in/slG4O on line 58
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
array(1) { ["service_nos"]=> string(3) "100" } Warning: count(): Parameter must be an array or an object that implements Countable in /in/slG4O on line 58 int(1)
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25
array(1) { ["service_nos"]=> string(3) "100" } int(1)

preferences:
169.36 ms | 402 KiB | 198 Q