Skip to content

PHP code snippet – How to remove NULL values in array ?

<?php
$arr = array('1', '', '2', '3', '0');
// Incorrect:
print_r(array_filter($arr));
// Correct:
print_r(array_filter($arr, 'strlen'));
//Custom
print_r(array_filter($arr, function ($val) {if ($val > 0) {return true;} else {return false;}}));
See also  CSS code snippet - How to change what twine looks like?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.