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

205
Vistas
Remove key from mixed array and reindex

I am new to postgresql with php. I get below array using pg_fetch_array() function.

Array
(
    [0] => 
    [name] => 
    [1] => 1
    [status] => 1
    [2] => C2005
    [code] => C2005
)

after removing index 1 and value of key status, i have to reindex this array so that expected output should become like:

Array
(
    [0] => 
    [name] => 
    [1] => C2005
    [code] => C2005
)

I tried

unset($row[1]);
unset($row['status'];
$foo = array_values($row);
echo "<pre>";
print_r($foo)
echo "</pre>";

and got output

Array
(
    [0] => 
    [name] => 
    [2] => C2005
    [code] => C2005
)

How the numeric index can be re-indexed after removing particular keys from the array?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can filter the array by their key. Live demo.

unset($array['status']);
$number_keys = array_values(array_filter($array, function($k){return is_int($k) && $k != 1;}, ARRAY_FILTER_USE_KEY));
$nonnumber_keys = array_filter($array, function($k){return is_string($k);}, ARRAY_FILTER_USE_KEY);
$result = array_merge($number_keys, $nonnumber_keys);
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