I have this array

Array
        (
            [0] => Array
                (
                    [post_category] => cat-1
                )

            [1] => Array
                (
                    [posts_count] => 33
                )

            [2] => Array
                (
                    [cells_num] => 1
                )

            [3] => Array
                (
                    [grid_num] => 0
                )

            [4] => Array
                (
                    [post_category] => cat-2
                )

            [5] => Array
                (
                    [posts_count] => 334
                )

            [6] => Array
                (
                    [cells_num] => 1
                )

            [7] => Array
                (
                    [grid_num] => 0
                )

            [8] => Array
                (
                    [post_category] => cat-3
                )

            [9] => Array
                (
                    [posts_count] => 321
                )

            [10] => Array
                (
                    [cells_num] => 2
                )

            [11] => Array
                (
                    [grid_num] => 0
                )

        )

note the repeated keys in the children arrays
I want to output something like

<?php

 array(
  [0] => array(
   [post_category] => cat-1
   [posts_count] => 33
   [cells_num] => 1
   [grid_num] => 0
  ),
  [1] => array(
  [post_category] => cat-2
  [posts_count] => 334
  [cells_num] => 1
  [grid_num] => 0
  ),
  [2] => array(
   [post_category] => cat-3
   [posts_count] => 321
   [cells_num] => 2
   [grid_num] => 0
  )
 );


?>

I assume $sourcearr is the array you shown above, your result array is $destarr

    $rowindex=-1;
    foreach($sourcearr as $key => $valuearr) 
    { 
        if ($key%4==0)
            $rowindex++;
        $value=current($valuearr);
        $destarr[$rowindex][key($valuearr)]=$value;   
    }


    echo "<pre>";
    print_r($destarr);
    echo "</pre>";

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.