Answer the question
In order to leave comments, you need to log in
Json getting data from array in Yii2?
Hi all. I am storing the value in the db as json. How to use in_array to select it in Yii2?
So, if the first entry, the category column in the news table is [1, 2, 5], and the second entry, the category column in the news table is [3, 7, 9], and the third entry, the category column in the news table is [2,5, 8], then do I need to have 2 number in the array in the column category;
How can I do that?
Answer the question
In order to leave comments, you need to log in
It happened,
public static function getTest($id,$lim){
$m = static::find()->all();
$massiv = [];
foreach ($m as $key) {
if(in_array($id,json_decode(json_encode($key['category']),true))){
$y = $key['id'];
array_push($massiv, $y);
}
}
return static::find()->where(['IN', 'id', $massiv])->orderBy(["id"=>SORT_DESC])->limit($lim)->all();
}
json. How to use in_array
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question