0

I have an array in php like

Array(
       [0]=>0
       [1]=>0
       [2]=>Array (
                   [0]=>60
                   [1]=>35
                  )
       [3]=>Array (
                  [0]=>60
                  [1]=>15
                  )
       [4]=>0
       [5]=>0
       [6]=>0
       [7]=>0
       [8]=>0
       )

what i want is take the values from this and insert in the another array such that the values of the sub_arrays are inserted on the same index of the new array what i want to achieve is

        Array(
       [0]=>0
       [1]=>0
       [2]=>60                    
       [3]=>35 
       [4]=>60
       [5]=>15          
       [6]=>0
       [7]=>0
       [8]=>0
       )

is there anyway to achieve this kindly help me

neer
  • 4,031
  • 6
  • 20
  • 34
Masooma Ahmad
  • 63
  • 1
  • 1
  • 7

2 Answers2

0

it will help you,

$array = array(array(1, 2, 3), array(4, 5, 6));
$result = array_reduce($array, 'array_merge', array());
print_r($result);

DEMO

Dave
  • 3,073
  • 7
  • 20
  • 33
0

Hello you can get this by using array iterator of php

$myArray = array(
   0=>0,
   1=>0,
   2=>array(
               0=>60,
               1=>35
              ),
   3=>Array (
              0=>60,
              1=>15,
              ),
   4=>0,
   5=>0,
   6=>0,
   7=>0,
   8=>0
   );

$myA =  new RecursiveIteratorIterator(new RecursiveArrayIterator($myArray));
$final = iterator_to_array($myA, false);


echo "<pre>";print_r($final);exit;

Please go through this let me know any issue exist or not.

Darshan ambaliya
  • 301
  • 3
  • 20