Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Nils-Fredrik/dde97d0e5c7b8020de08aed948eab59f to your computer and use it in GitHub Desktop.
Save Nils-Fredrik/dde97d0e5c7b8020de08aed948eab59f to your computer and use it in GitHub Desktop.
array_filter and strlen to filter array
<?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
)
@bkdotcom
Copy link

As of PHP 8.1, strlen will now emit a deprecated error "strlen(): Passing null to parameter #1 ($string) of type string is deprecated"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment