Php 数组的yii循环序列名称

Php 数组的yii循环序列名称,php,arrays,loops,yii,indexing,Php,Arrays,Loops,Yii,Indexing,我的数组如下: radiolist = array (k1=>'1',k2=>'3',k3=>'2',k4=>'1',k5=>'2',k6=>'2'); 在我的表格中,我想根据以下代码重复这些数组索引和值: for ($i = 0; $i <= count($radiolist)-1; $i++) { echo $form->radioButtonList($model,'k[$i]',array('1'=>'1','2'=>

我的数组如下:

radiolist = array (k1=>'1',k2=>'3',k3=>'2',k4=>'1',k5=>'2',k6=>'2');
在我的表格中,我想根据以下代码重复这些数组索引和值:

for ($i = 0; $i <= count($radiolist)-1; $i++) {  
  echo $form->radioButtonList($model,'k[$i]',array('1'=>'1','2'=>'2','3'=>'3'));
  //'k[$i]' repeated to be k1, k2, k3, k4, k5, k6   
}
for($i=0;$i radioButtonList($model,'k[$i]”,数组('1'=>'1','2'=>'2','3'=>'3');
//“k[$i]”重复为k1、k2、k3、k4、k5、k6
}
我想要这个输出:

<input type="radio" name="school[k1]" value="1" /> 1
<input type="radio" name="school[k1]" value="2" /> 2
<input type="radio" name="school[k1]" value="3" /> 3
.
.
.
<input type="radio" name="school[k6]" value="1" /> 1
<input type="radio" name="school[k6]" value="2" /> 2
<input type="radio" name="school[k6]" value="3" /> 3
1
2.
3.
.
.
.
1.
2.
3.
我真的不知道该怎么做。请提供任何建议,我们将不胜感激


谢谢。

如果您只想重复这些数组索引和值,radioButtonList()自己会帮您完成的

<?php $radiolist = array ('k1'=>'1','k2'=>'3','k3'=>'2','k4'=>'1','k5'=>'2','k6'=>'2');  ?>
<?php echo $form->radioButtonList($model,'school',$radiolist,
   array(
     'template'=>'{input}{label}',
     'separator'=>'',
     'labelOptions'=>array(
            'style'=> '
                padding-left:13px;
                width: 60px;
                float: left;
            '),

      ));?>
?>

?>

尝试几种组合后,以下是我的解决方案:

$k = array ('k1','k2','k3','k4','k5','k6');

for ($i = 0; $i <= count($k)-1; $i++) {  
   echo $form->radioButtonList($model,$k[$i], array('1'=>'1','2'=>'2','3'=>'3'));
   //$k[$i] would repeated to be k1, k2, k3, k4, k5, k6   
   //$i as index or use other index as u want.
}
$k=数组('k1','k2','k3','k4','k5','k6');
对于($i=0;$i radioButtonList($model,$k[$i],数组('1'=>'1','2'=>'2','3'=>'3'));
//$k[$i]将重复为k1、k2、k3、k4、k5、k6
//$i作为索引或根据需要使用其他索引。
}
非常感谢你的建议。
干杯。

仍然不是我想要的。当我用它来更新我的表格时,这成了一个问题。