PHP循环试图用codeigniter重复数组字符串

时间:2015-11-20 21:00:15

标签: php codeigniter

我在CodeIgniter中运行此代码:

for($j=0;$j<count($detials);$j++){
    $newValues = array(
        'Description' => $detials[$j]
    );
}

目前它输出:

Array ( [Description] => Array ( [0] => this [1] => is [2] => a [3] => name ) )

我希望循环创建它:

$newValues = array(
    'Description' => $detials[1]
    'Description' => $detials[2]
    'Description' => $detials[3]
);

我该怎么做?

1 个答案:

答案 0 :(得分:1)

我不确定,但我认为您可能会尝试这样做:

for($j=0;$j<count($detials);$j++){
    $newValues[] = array('Description' => $detials[$j]);
}

哪个会给你这个数组:

$newValues = array(
    array('Description' => $detials[1]),
    array('Description' => $detials[2]),
    array('Description' => $detials[3])
 );