Jump to content

[SOLVED] using foreach to add new array


jagoan-neon

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/151623-solved-using-foreach-to-add-new-array/
Share on other sites

$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]
                      );
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.