数组未传递正确的值

时间:2012-08-24 00:04:38

标签: php

我有以下变量,需要在数组循环中使用它...

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

请检查我在哪里做错了?

2 个答案:

答案 0 :(得分:5)

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

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

答案 1 :(得分:0)

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


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