• Home
  • Android
  • Programming
    • Object Oriented Programming
  • PHP
  • Contact

bitcaal.com

  • Home
  • Android
  • Programming
    • Object Oriented Programming
  • PHP
  • Contact

Remove null values from an Array in PHP

bymehadi March 6, 2020 PHP

Today we will see how we can easily remove any null value from an Array in PHP. For this we will use array_filter() function. And the important thing is we don’t need any loop to complete the task. So lets see the example.

Table Of Contents

  1. Example
  2. Output

Example


$data = array("Mehadi Hasan", "Hello User", null, 11, "",null, 77,"Here is the data");
 
$output = array_filter($data, function($value) {
			  return !is_null($value);
			});
print_r($output);

Output


Array
(
    [0] => Mehadi Hasan
    [1] => Hello User
    [3] => 11
    [4] => 
    [6] => 77
    [7] => Here is the data
)
TaggedPHPPHP ArrayRemove null values from an Array in PHP

Rubik's Cube, 3D Combination Puzzle

Leave a Reply Cancel reply

5 × three =

Recent Posts

  • Remove null values from an Array in PHP
  • Rubik’s Cube, 3D Combination Puzzle
  • Object-Oriented Programming Concepts: Constructor & Destructor
  • 5 Best New Latest Technology
  • How to Change The App Language Programmatically in Android

Categories

  • Android Basic
  • Object Oriented Programming
  • PHP
  • Programming
  • Technology

Recent Comments

  • JohnDoes on How to Change The App Language Programmatically in Android
© bitcaal 2020