<?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='service[0][tier][0][schedule][0][amount]=10';//'discount_rule[0][service_no][0][service_nos]=100';
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 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- array(1) {
["schedule"]=>
array(1) {
[0]=>
array(1) {
["amount"]=>
string(2) "10"
}
}
}
int(1)
preferences:
143.83 ms | 404 KiB | 181 Q