How to use in(1,2,5) yii2

I want to know how can i get all data of user with array id for where condition

In yii you could do something like this


$students = Student::model()->findAll("id IN ({$_POST['studentIds']})");

or




$criteria = new CDbCriteria();

$criteria->addInCondition("id", array(1,2,3,4));

$result = Student::model()->findAll($criteria);



or




$userDtls = Student::model ()->findAllByAttributes ( array (

                    'id' => explode ( ",", $_POST ['studentIds'] ) 

            ) );



Now in yii2 CDbCriteria is not there, so which approach should i use to achieve same thing??

I have tried this but it only returns data for first id in the array


$result = Users::findAll([ 'id'=> $_POST ['keylist']]);

In documentation it is written that we can use this


$result = Users::findAll([1,488,489]);

But my array $_POST[‘keylist’] is something like this




keylist{

   0='1'

   1='5'

   2='8'

}



Thats why it doesnt work i guess

thank you

thank you

If your $_POST[‘keylist’] looks like you said it looks there should be no problem with getting results with


Users::findAll($_POST['keylist']);

Yes i got it

thank you for your replay

The problem was something else

keylist was returning the id of event table where as i wanted id of user table

so i changed the key value of checkbox and than it was solved

thank you