How to Remove Null Values from Array in PHP?

By Hardik Savani May 14, 2024 Category : PHP

Hey Artisan,

This tutorial is focused on How to remove null values from array in PHP. step by step explain remove null values from array php. you can see php remove null values from array. I explained simply step by step php array_filter is not null.

you have array with null value and you want to remove all null value from that array without loop. you can remove your all null value from array without loop. PHP array_filter function through you can remove all null value, you see following example how to remove null value :

Example:

<?php

$array = array("Google", "", 0, 2, null, -5, "0", "Yahoo", 10, false);

/* Filtering the array */

$result = array_filter($array);

var_dump($result);

?>

Output:

Array

array(5) {

[0]=>

string(5) "Google"

[3]=>

int(2)

[5]=>

int(-5)

[7]=>

string(6) "Yahoo"

[8]=>

int(10)

}

Try this.......

Tags :
Shares