在数组php内增加1值

时间:2016-11-05 11:20:04

标签: php codeigniter

for($n = 0; $n <= 5; $n++)
 {
    $some =   $n+1 ;
 }
    $dataSubActivity[]=array(
    'showSubid' => $some,
    'activityMainId'=> $activityMainId,
    'activitySubTitle'=> $activitySubTitle,
    'descSub'=> $description,
    'unit'=> $unit,
    'quantity'=> $quantity);

上面的代码是一个我希望将“showSubid”增加1的数组 所以结果应该是1,2,3,4等 请提出一些想法

2 个答案:

答案 0 :(得分:1)

尝试:

for ($n = 0; $n <= 5; $n++) {
      // put it inside loop
      $dataSubActivity[]=array(
        'showSubid' => $n+1,
        'activityMainId'=> $activityMainId,
        'activitySubTitle'=> $activitySubTitle,
        'descSub'=> $description,
        'unit'=> $unit,
        'quantity'=> $quantity);
}

答案 1 :(得分:1)

使用这个

for($n = 0; $n <= 5; $n++)
{
    $some =   $n+1 ;

    $dataSubActivity[]=array(
    'showSubid' => $some,
    'activityMainId'=> $activityMainId,
    'activitySubTitle'=> $activitySubTitle,
    'descSub'=> $description,
    'unit'=> $unit,
    'quantity'=> $quantity);
}