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 git.master, git.master_jit, rfc.property-hooks
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.

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:
62.73 ms | 401 KiB | 8 Q