Answer the question
In order to leave comments, you need to log in
[[+content_image]]
How to clear an array recursively?
We have this array:
Array ( [chat_id] => 317373696 [text] => test [reply_markup] => {"inline_keyboard":[[{"text":"category","url":null,"login_url":null,"callback_data":"test2","switch_inline_query":null,"switch_inline_query_current_chat":null,"callback_game":null,"pay":null},{"text":"category 2","url":null,"login_url":null,"callback_data":"test3","switch_inline_query":null,"switch_inline_query_current_chat":null,"callback_game":null,"pay":null}]]} )
Answer the question
In order to leave comments, you need to log in
It's decided.
function isJson($string)
{
return is_string($string) && is_array(json_decode($string, true)) ? true : false;
}
function array_clear($array)
{
foreach ($array as $k => $v)
{
if (is_array($v))
{
$array[$k] = array_clear($array[$k]);
}
elseif (isJson($v))
{
$array[$k] = json_encode(array_clear(json_decode($v, 1)));
}
elseif (empty($v))
{
unset($array[$k]);
}
}
return $array;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question