2012-08-24 28 views
-1

我有以下變量,需要在陣列循環使用它...陣列沒有通過正確的價值

$jointa="'nike-score', 'pack-cupcake', 'shor-burgundy'"; 

foreach (array($jointa) as $id) { 
    $yourSiteContent[] = array('permalink' => $id, 'updated' => $dated); 
} 

但是當我把直接值在數組循環的優良工程....

foreach (array('nike-score', 'pack-cupcake', 'shor-burgundy') as $id) { 
    $yourSiteContent[] = array('permalink' => $id, 'updated' => $dated); 
} 

請檢查我在做什麼錯誤?

+1

'S /陣列($ jointa)/爆炸( '',$ jointa)/'你的第一個片段。 – raina77ow

+1

事情是''jointa'是一個字符串不是數組。那麼你將它作爲一個數組,使得它的'array(0 => string)'而不是你想要的數組 –

回答

5
$jointa = array('nike-score', 'pack-cupcake', 'shor-burgundy'); 

foreach ($jointa as $id) { 
    $yourSiteContent[] = array('permalink' => $id, 'updated' => $dated); 
} 
0
$jointa = array('nike-score', 'pack-cupcake', 'shor-burgundy'); 


foreach ($jointa as $key => $value) 
{ 
    echo($key . " = " . $value) 
}