在ArrayHelper :: map()中Yii2连接自动增量字母表

时间:2016-04-07 05:12:07

标签: php yii2

这是我的activeRadioList

<?= Html::activeRadioList($model, 'qa_value', ot\QuestionAnswer::getAnswerOptions($model), [
            'encode' => false, 
            'separator' => '<br/>',
            'itemOptions' => [
                'labelOptions' => ['class' => 'radio-inline']
            ],              
        ]);  ?>

这是我的getAnswerOption()函数来获取选项值

public static function getAnswerOptions($qModel)
{
    $answerData = $qModel->qaQuestionInstance->getTqiQuestionAns()->asArray()->all();
    return \yii\helpers\ArrayHelper::map($answerData, 'qna_id', function ($model) {
        $l = 'a';
        return $l++.'. '.$model['qna_answer'];
    });    
}

这是这样的回报

enter image description here

但我想要

一个。错误

湾真

1 个答案:

答案 0 :(得分:0)

是的,我在getAnswerOptions()功能

中更改输出
public static function getAnswerOptions($qModel)
{
    $answerData = $qModel->qaQuestionInstance->getTqiQuestionAns()->asArray()->all();
    $l = 'a';
    $i = 0;
    foreach ($answerData as $ad)
    {
        $answerData[$i++]['qna_answer'] = ($l++.'. &nbsp;'.$ad['qna_answer']); 
    }
    return \yii\helpers\ArrayHelper::map($answerData, 'qna_id', function ($model) {
        return $model['qna_answer'];
    });    
}