Skip to content

Instantly share code, notes, and snippets.

@2ik
Last active February 17, 2018 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2ik/45ab356972b0d3c6c36ea1c432d8b763 to your computer and use it in GitHub Desktop.
Save 2ik/45ab356972b0d3c6c36ea1c432d8b763 to your computer and use it in GitHub Desktop.
Функция очистки многомерного массива от пустых значений с сохранением порядка нумерации ключей
function array_clean($array) {
if(!is_array($array)) return;
foreach($array as $key => $value) {
if(!is_array($value)){
$array[$key] = trim($value);
if(strlen($value)==0)
unset($array[$key]);
}
else
$array[$key] = array_clean($value);
}
return array_values($array);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment