jagoan-neon Posted March 29, 2009 Share Posted March 29, 2009 Hi all, I have this code : for ( $i = 0; $i < count($id_list); $i++) { $array = Array ( $i => Array('id' => "$id_list[$i]", 'traffic' => "$kunjungan_list[$i]", 'rekrut' => "$rekrut_list[$i]", 'input_data' => "$input_list[$i]", 'sms' => "$sms_list[$i]", 'poll' => "$poll_list[$i]" ), ); } When i view the result is : Array ( [389] => Array ( [id] => gempar [traffic] => 8146 [rekrut] => 273 [input_data] => 20 [sms] => 14 [poll] => 1 ) ) How to add all data? I want to have Array from 0 to 389, not 389 only Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/151623-solved-using-foreach-to-add-new-array/ Share on other sites More sharing options...
wildteen88 Posted March 29, 2009 Share Posted March 29, 2009 $array = array(); for ( $i = 0; $i < count($id_list); $i++) { $array[$i] = array( 'id' => $id_list[$i], 'traffic' => $kunjungan_list[$i], 'rekrut' => $rekrut_list[$i], 'input_data' => $input_list[$i], 'sms' => $sms_list[$i], 'poll' => $poll_list[$i] ); } Quote Link to comment https://forums.phpfreaks.com/topic/151623-solved-using-foreach-to-add-new-array/#findComment-796307 Share on other sites More sharing options...
jagoan-neon Posted March 29, 2009 Author Share Posted March 29, 2009 PHPFreaks is the best! Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/151623-solved-using-foreach-to-add-new-array/#findComment-796310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.