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

216
Views
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 answers
Answer question

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 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!