How to Remove Null Values from Array in 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:
Arrayarray(5) {
[0]=>
string(5) "Google"
[3]=>
int(2)
[5]=>
int(-5)
[7]=>
string(6) "Yahoo"
[8]=>
int(10)
}
Try this.......
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Replace \n with br in PHP?
- PHP Google Recaptcha V2 Example Tutorial
- How to Add Text Watermark to Image in PHP?
- PHP explode() Function Example Tutorial
- PHP - How to Remove Blank Pages from PDF File?
- PHP Check If Array Is Multidimensional or Not
- How to Convert Object into Array in PHP?
- How to Get Maximum Key Value of Array in PHP?
- How to Remove Empty Values from Array in PHP?
- How to Add Prefix in Each Key of PHP Array?
- How to Get Minimum Key Value of Array in PHP?
- How can Make an Array from the Values of Another Array's Key Value?
- How to Merge Two Array with Same Keys without Loop in PHP?