2013-07-18 93 views
0

我需要一些幫助。Array上包含的顯示陣列

我有這樣的數組結構。

$data = array(
     'id_packet' => NULL, 
     'name_packet' => NULL, 
     'number_of_users' => NULL, 
     'number_of_blogs' => NULL, 
     'number_of_accounts' => NULL, 
     'price' => NULL, 
     'period' => NULL, 
     'status' => 1, 
); 

'number_of_users' => NULL, 'number_of_blogs' => NULL, 'number_of_accounts' => NULL,是在一個數據庫中的以下搜索結果:

$n=1; 
foreach ($list_component as $dt) { 
     $comp[$n] = $dt->name_comp; 
     echo "'".$comp[$n]."' => NULL,"; 
     $n++; 
} 

,它已成功地顯示了預期的結果。

我想問一下,如何在上面的$ data數組中包含'number_of_users' => NULL, 'number_of_blogs' => NULL, 'number_of_accounts' => NULL,

我一直在尋找一些參考,但還沒有設法找到任何。 也許你們中的一個人可以幫忙或有任何想法? 謝謝。

框架:爾康

回答

0

你可以這樣做

$data = array(
     'id_packet' => NULL, 
     'price' => NULL, 
     'period' => NULL, 
     'status' => 1, 
); 
$n=1; 
foreach ($list_component as $dt) { 
     $comp[$n] = $dt->name_comp; 
     $data[$comp[$n]]= NULL; 
     $n++; 
} 
0

東西試試這個:

foreach ($data as $key => $value){ 
    if (empty($value)){ 
     $disp = 'NULL'; 
    } else { 
     $disp = $value; 
    } 
    echo "'".$key."' = ".$disp.",\n"; 
}