$ids = implode(',', $productsIds); //получается просто 2,3,4 $products = Product::find() ->where(['id'=>[$ids],'status'=>'1']) //так не работает(выводит только первый товар) ->all(); $products = Product::find() ->where(['id'=>[2,3,4],'status'=>'1']) //если просто подставлю числа , то все работает ->all(); 

What could be the reason?

    1 answer 1

    You array put a line. It is necessary so:

     ->where(['id'=>$productsIds,'status'=>'1']) 

    Remove implod.

    • does not work and so. So there in the query the idea should be inserted a line - Kolya Vantukh
    • Why does the query contain a string? What do you have in var_dump ($ productsIds) - zabachok
    • In many examples I have seen how it was done through implode. In var_damp I have array (3) {[0] => int (2) [1] => int (3) [2] => int (4)} - Kolya Vantukh
    • thanks, now everything works as it should - Kolya Vantukh