Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

358
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda