-1

I have an array like this from cdbcommand select query. (Using Yii)

Array(
    [0] => Array(
            [0] => Array
                (
                    [id] => 21
                )

            [1] => Array
                (
                    [id] => 91
                )

            [2] => Array
                (
                    [id] => 125
                )
        )

    [1] => Array
        (
            [0] => Array
                (
                    [id] => 15
                )
        )
)

I want final array like array(21, 91, 125, 15)

How can I do this?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Rakhi
  • 1
  • 2
  • possible duplicate of [How to Flatten a Multidimensional Array?](http://stackoverflow.com/questions/1319903/how-to-flatten-a-multidimensional-array) – hfs Feb 14 '14 at 12:19

2 Answers2

1
$output=array();    
foreach($result as $row){
        foreach($row as $id_container){
            $output[]=$id_container["id"];
        }
    }

This will give you what you need, if array structure is dependable - then it wont work.

Let me see
  • 5,063
  • 9
  • 34
  • 47
ineersa
  • 3,445
  • 30
  • 40
0

try this

$newArray=array();
foreach($result as $value)
{
array_merge($newArray,array_values($value));
}
Let me see
  • 5,063
  • 9
  • 34
  • 47