How to set variable value in radiolist

Hello Experts,

Can you guide me how to set variable in the radiolist?

In regular basis we use below code:

<?= $form->field($model, 'number')->radioList(array('1'=>'One',2=>'Two')); ?>


This is sort of static case.

But if I want to set some variable in the radioist like below, how to do that?

I want something like below:

<?= $form->field($model, 'number')->radioList(array($number1=>$number1,$number2=>$number2)); ?>

Thanks in advance.



Hi there, you can create an array using a loop


$radioListOptions = [];

for ($i = 0; $i < 10; $i++) {

  $radioListOpions[$i] = $i;



<?= $form->field($model, 'number')->radioList($radioListOptions); ?>