Created
April 2, 2016 18:15
-
-
Save Nils-Fredrik/dde97d0e5c7b8020de08aed948eab59f to your computer and use it in GitHub Desktop.
array_filter and strlen to filter array
This file contains 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 | |
$array = array( | |
0, | |
'', | |
false, | |
1, | |
'0' | |
); | |
print_r( $array ); | |
print_r( array_filter( $array, 'strlen' ) ); | |
?> | |
Produce: | |
Array | |
( | |
[0] => 0 | |
[1] => | |
[2] => | |
[3] => 1 | |
[4] => 0 | |
) | |
Array | |
( | |
[0] => 0 | |
[3] => 1 | |
[4] => 0 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of PHP 8.1,
strlen
will now emit a deprecated error "strlen(): Passing null to parameter #1 ($string) of type string is deprecated"