<?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 removeEmptyParameter($array)
{
$newArray = array();
if(is_array($array))
{
foreach($array as $key => $value)
{
if(is_array($value))
{
$value = removeEmptyParameter($value);
}
if(!empty($value) || $value ==="0")
{
$newArray[$key] = $value;
}
}
return $newArray;
} else {
if(!empty($array) || $array ==="0")
{
$newArray[$key] = $array;
return $newArray;
}
}
}
function isMultiDimensional($array)
{
if(is_array($array)) {
foreach ($array as $key=>$value){
if(is_array($value)){
return true;
}
}
}
return false;
}
$string = 'rest_call=create_acct_complete_m&acct[acct_row][country]=US';
$cat = 'admintools-api';
parse_str($string, $output);
$method = $output['rest_call'];
$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' || $method=='create_acct_complete_m') {
if(isMultiDimensional($c) || (array_keys($c)[0] != $row.'s' ) ){
$c = removeEmptyParameter($c);
$options[$key][$k][$row][$r]=$c;
} else {
$options[$key][$k][$row][$r]=array_values($c)[0];
}
} else {
$options[$row][$r]=$c;
}
}
} else {
if($cat=='core-api') {
($key == $row) ? ($options[$key][$k] = $column)
: ($options[$key][$k][$row]
= $column);
} else {
$column=removeEmptyParameter($column);
$options[$row][$k] = $column;
}
}
}
}
}
$apiLiveOptions[$key] = $apiLiveArray;
}
} else {
$options[$key] = $value;
$apiLiveOptions[$key] = $value;
}
};
var_dump($options);
- Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- Warning: Undefined variable $key in /in/QL6d0 on line 40
array(2) {
["rest_call"]=>
string(22) "create_acct_complete_m"
["country"]=>
array(1) {
["acct_row"]=>
array(1) {
[""]=>
string(2) "US"
}
}
}
- Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
- Notice: Undefined variable: key in /in/QL6d0 on line 40
array(2) {
["rest_call"]=>
string(22) "create_acct_complete_m"
["country"]=>
array(1) {
["acct_row"]=>
array(1) {
[""]=>
string(2) "US"
}
}
}
- Output for 7.3.32 - 7.3.33
- array(2) {
["rest_call"]=>
string(22) "create_acct_complete_m"
["country"]=>
array(1) {
["acct_row"]=>
array(1) {
[""]=>
string(2) "US"
}
}
}
preferences:
206.56 ms | 402 KiB | 330 Q