php - How to fetch array in correct order -
how fetch array in correct order ?
i printing array not fetching in correct order.
i want each track value contain array of date , array of number respectively. please give solution .any highly appreciated.
my code fetch array are:
<?php foreach($posts $post) { $array['track_value'][] = $post->track_value; $array['track_value']['date'][] = $post->date; $array['track_value']['num'][] = $post->num; } ?>
from getting wrong value 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 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 ) ) ) ) ?>
i'm not sure trying do, maybe on way:
foreach($posts $post) { $array['track_value'][$post->track_value]['date'][] = $post->date; $array['track_value'][$post->track_value]['num'][] = $post->num; }
this give output like:
array( 'track_value' => array( 'mobile' => array( 'date' => array( 0 => '2015-08-25', 1 => '2015'08'26', ), 'num' => array( 0 => 1337, 1 => 13337, ), ), 'pc' => ... ), )
Comments
Post a Comment