Your request is something like this:
SELECT title FROM topics WHERE id IN (1,2,3);
So you get an array of array. You also need to complete the request.
Try it -
$query = (new \yii\db\Query())->select(['title'])->from('topics')->where(['id' => [1, 2, 3]]); $command = $query->createCommand(); $data = $command->queryAll(); $titles = ''; foreach($data as $row) { $titles .= $row['title'] . ', '; } return rtrim($titles, ', ');
You will get a title for each entry, separated by a comma.
source share