Created
August 29, 2017 15:35
-
-
Save sectsect/c8491d99ee557fa1f37d04688165ee18 to your computer and use it in GitHub Desktop.
The strict empty check for PHP array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function array_remove_empty( $array ) { | |
foreach ( $array as $key => $value ) { | |
if ( is_array($value) ) { | |
$array[$key] = array_remove_empty( $array[$key] ); | |
} | |
if ( empty( $array[$key] ) ) { | |
unset( $array[$key] ); | |
} | |
} | |
return $array; | |
} | |
function is_array_empty( $array ) { | |
$array = array_remove_empty( $array ); // Remove empty array | |
$array = array_filter( (array) $array ); | |
if ( empty($array) ) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage Example