Remove Null values in PHP array

you want to remove all null value from an array without any loop. you can remove all null value from array without loop.I am explaining you, how to remove null value from an array. let’s see example how to remove null value :

<?php
  
    $data = array(5000, "Azhar", null, "shaikh", NULL, "", 41, 457, 451);
 
	$result = array_filter($data, function($section) {
				  return !is_null($section);
				});
	print_r($result);
?>

Result:

Array
(
    [0] => 5000
    [1] => Azhar
    [3] => shaikh
    [5] => 
    [6] => 41
    [7] => 457
    [8] => 451
)

Leave a Reply

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

2 + 5 =