How to remove all empty/null values in an array using PHP

  1. If you have an array with empty values and you wish to remove the empty valuesyou can use the following one line code
    		$array = array('','1','','3');
    		$array = array_filter($array, 'strlen');
    		echo '<pre>';
    		echo '</pre>';
  2. The result will be only the NOT NULL values
        [1] => 1
        [3] => 3

Image Credits: Photo by Isis França on Unsplash.

More Similar Posts

No results found.