Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda