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

403
Views
Remove parent array from multidimensional array in php

using php how to get array result into below way,

 Array
    (
        [3] => Array
            (
                [15] => 15
                [16] => 16
                [17] => 17
                [18] => 18
                [19] => 19
            )

    )

how to convert above array into below format,

 Array
        (
            [0] => 15
            [1] => 16
            [2] => 17
            [3] => 18
            [4] => 19
        )
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

array_values() is your friend;

Presuming your array exists in a variable called $array;

$newArray = array_values($array[3]);
about 4 years ago · Santiago Trujillo Report

0

you should use RecursiveArrayIterator to remove parent array

$arr = new RecursiveIteratorIterator(new RecursiveArrayIterator($multidimensional_array));
$new_arr = iterator_to_array($arr, false);
about 4 years ago · Santiago Trujillo Report

0

try this, if you have more than one sub-array, it will work.

$arr = array(3 =>
        array
          ( 
           15  => 15,
           16 => 16,    
           17    => 17,  
           18    => 18,  
           19    => 19
          )
        );
    $new = array();
        foreach ($arr as $v){
            $new = array_merge($new , array_values($v)) ;
        }
echo "<pre>"; print_r($new);

Working Demo

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