dreamwest Posted July 3, 2010 Share Posted July 3, 2010 Im trying to specify keys for associative arrays but ive never done it before other than via mysql This: $srt = 1; $end = 10; while ($srt < $end) { $arr[]= $srt; ++$srt; }//end while print_r ($arr); Outputs: (10 loops) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 ) But how can i get it like this: (1 loop example) Array ( [0] => Array ( [q_id] => 1 [q_v_id] => 857434 [q_session] => fe13c9e53d1e6d0170a59f88c6327547 ) ) Link to comment https://forums.phpfreaks.com/topic/206593-array/ Share on other sites More sharing options...
Psycho Posted July 3, 2010 Share Posted July 3, 2010 $theArray = array ( 0 => array ( 'q_id' => 1, 'q_v_id' => 857434, 'q_session' => fe13c9e53d1e6d0170a59f88c6327547 ) ); print_r($theArray); Link to comment https://forums.phpfreaks.com/topic/206593-array/#findComment-1080561 Share on other sites More sharing options...
dreamwest Posted July 3, 2010 Author Share Posted July 3, 2010 Thanks! I think i undestand it now $srt = 1; $end = 10; while ($srt < $end) { $arr[]= array('q_id' => $srt, 'field2' => barry, 'field3' => german) ; ++$srt; }//end while print_r ($arr); Link to comment https://forums.phpfreaks.com/topic/206593-array/#findComment-1080569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.