How to fetch array in correct order ?
I am printing a array but it is not fetching in correct order.
I want that each track value contain array of date and array of number respectively. please give a solution .Any help would be highly appreciated.
My code for fetch array are:
<?php
foreach($posts as $post)
{
$array['track_value'][] = $post->track_value;
$array['track_value']['date'][] = $post->date;
$array['track_value']['num'][] = $post->num;
}
?>
From this i am getting wrong value like these:
<?php
Array (
[track_value] => Array
(
[0] => mobile
[date] => Array
(
[0] => 2015-08-23
[1] => 2015-08-24
[2] => 2015-08-23
[3] => 2015-08-24
[4] => 2015-08-22
[5] => 2015-08-23
[6] => 2015-08-24
)
[num] => Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 2
[4] => 1
[5] => 1
[6] => 1
)
[1] => mobile
[2] => laptop
[3] => laptop
[4] => pc
[5] => pc
[6] => pc
)
)
?>
The output should be like:
<?php
Array (
[track_value] => Array
(
[0] => mobile
Array
(
[date] => Array
(
[0] => 2015-08-23
[1] => 2015-08-24
)
[num] => Array
(
[0] => 1
[1] => 1
)
)
[1] => laptop
Array
(
[date] => Array
(
[0] => 2015-08-23
[1] => 2015-08-24
)
[num] => Array
(
[0] => 1
[1] => 2
)
)
[2] => pc
Array
(
[date] => Array
(
[0] => 2015-08-23
[1] => 2015-08-24
[2] => 2015-08-23
)
[num] => Array
(
[0] => 1
[1] => 1
[2] => 1
)
)
)
)
?>