Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

348
Views
How to remove null values in multi-dimensional array?

I want to remove null values from this array.

Array(
    [0] => Array( [fcmToken] => 123 )
    [1] => Array( [fcmToken] => )
    [2] => Array( [fcmToken] => 789 )
)

Expected Results

Array(
    [0] => Array( [fcmToken] => 123 )
    [1] => Array( [fcmToken] => 789 )
)
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Use array_filter with a callback:

$r = array_filter($array, function($v) { return !empty($v['fcmToken']); });

For checking exactly null:

$r = array_filter($array, function($v) { return !is_null($v['fcmToken']); });
over 4 years ago · Santiago Trujillo Report

0

Here we are using foreach to iterate over values and using $value for non-empty $value["fcmToken"]

$result=array();
foreach($array as $key => $value)
{
    if(!empty($value["fcmToken"]))
    {
        $result[]=$value;
    }
}

print_r($result);

Output:

Array
(
    [0] => Array
        (
            [fcmToken] => dfqVhqdqhpk
        )

    [1] => Array
        (
            [fcmToken] => dfgdfhqdqhpk
        )

)
over 4 years ago · Santiago Trujillo Report

0

The best and easy single line solution for filter multidimensional array like below.

$aryMain = array_filter(array_map('array_filter', $aryMain));

I hope this solution is work for you. for more detail please visit below link.

PHP: remove empty array strings in multidimensional array

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!