
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How to remove null values with PHP?
To remove null value in PHP, use array_filter(). It filters the array values. Let’s say the following is our array −
$studentDetails = array("firstName" => "John", "lastName"=> null); echo "The original value is=";print_r($studentDetails);
Let’s filter with array_filter() −
$result = array_filter($studentDetails);
Example
<!DOCTYPE html> <html> <body> <?php $studentDetails = array("firstName" => "John", "lastName"=> null); echo "The original value is="; print_r($studentDetails); $result = array_filter($studentDetails); echo "</br>"; echo "After removing null part,the result is="; print_r($result); ?> </body> </html>
Output
The original value is=Array ( [firstName] => John [lastName] => ) After removing null part,the result is=Array ( [firstName] => John )
- Related Articles
- How to remove NULL values from a list in R?
- Python - Remove a column with all null values in Pandas
- How to handle Null values while working with JDBC?
- How does COALESCE order results with NULL and NON-NULL values?
- How to avoid inserting NULL values to a table with JavaScript?
- PHP NULL
- How to count null values in MySQL?
- How to assign values to an array with null/empty objects in JavaScript?
- MySQL queries to update date records with NULL values
- What operators C# provides to deal with null values?
- Fetch maximum value from multiple columns with null and non-null values?
- How can we handle NULL values stored in a MySQL table by using PHP script?
- Update all the fields in a table with null or non-null values with MySQL
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL
- Setting null values with an HTML using AngularJS.

Advertisements