Foreach in DetailView

Hello,

I have a one-to-many relationship between two tables.

Table 1 - customer details

Table 2 - product rating (There are many products and they rate as many as they like)

In the detail view of table 1, I would like to include a list of the products they have rated in table 2. I have created the following code within the model for table 1 and it is working well:


    public function getSurveyResponse()

    {

        return $this->hasMany(SurveyResponse::className(), ['visit_id' => 'visit_id']);

    }


    public function getQuestionText(){

        $questions = [];

        foreach ($this->surveyResponse as $question ){

            $questions[] = $question['question_text'];

        }

        return $questions;

    }

$questions contains the array of questions. (The answers are also in table2, so I would do something similar for that)

I can access a single item from the $questions array in the DetailView by doing this:


            [

                'label' => 'Answer',

                'value' =>  $model->questionText[2],

            ],

But what I would really like to do is display a list of the questions they have answered. Ideally I would display the question in the left-hand column and the answer in the right-hand column like this:


(output from the table1)

-------------------------------------

email                  |  person@email.com

name                   |  bob smith

--------------------------------------

(output from the foreign table2)

please rate product A  |  3

please rate product B  |  5

please rate product F  |  3

Any help would be most appreciated.

Many thanks