I created a working function for splitting following associative array into two numeric array. I wonder if there is a better method , avoid looping.
I have an array as follows.
Array ( [0] => stdClass Object ( [CreatedAt] => 16/02/2014 [Occurrence] => 1 ) [1] => stdClass Object ( [CreatedAt] => 17/02/2014 [Occurrence] => 8 ) [2] => stdClass Object ( [CreatedAt] => 18/02/2014 [Occurrence] => 4 ) [3] => stdClass Object ( [CreatedAt] => 20/02/2014 [Occurrence] => 11 ) )
Need to convert it into two numerical array
Array ( [0] => 16/02/2014 [1] => 17/02/2014 [2] => 18/02/2014 [3] => 20/02/2014 ) Array ( [0] => 1 [1] => 8 [2] => 4 [3] => 11 )
I used a foreach
loop
$array1 = array(); $array2 = array(); foreach ($mainArray as $key => $value) { $array1[] = $value->CreatedAt; $array2[] = $value->Occurrence; } print_r($array1); print_r($array2);
But if I have 1000 rows in mainArray, it will affect the performance. If you have a better solution, let us all know that.