D
D
ddddd tttt2019-01-13 16:21:00
Yii
ddddd tttt, 2019-01-13 16:21:00

How to return data from ActiveRecord as an array of values, not objects?

return PathFile::find()->select('path')->where(['customer_id' => $this->customer_id])->asArray()->all();
[{"path":"........................"},{"path":".......... .."},{"path":"........."}]
Is there a built-in method to return data in the format: ["path":"........... .............", "path":"............", "path":"........."] or preferably ["........................","............", ".... ....."] ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan Shumov, 2019-01-13
@inoise

Someone needs ArrayHelper::getColumn

M
morricone85, 2019-01-13
@morricone85

["........................","............", "...... ..."]

Is that what you are hinting at?

R
Ruslan Makhin, 2019-01-14
@rusya_mahin_page

foreach
in your hands and in front of you with the song
For, if I understand correctly, you want to combine everything into 1 array (["........................ ","............", "........."])
but if you have the same keys - then the idea itself is bad... But thanks to the loop - you can transform the array as you like

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question