0

I have an array of elements in the form of:

Array ( [0] => 16 [1] => 14 [2] => 1 [3] => 13 )

Now I need to extract only rows which ID is not one of the values in the array. Right now I'm using the following code:

$items = ArrayHelper::map(User::find()->where(['<>', 'id', $array])->all(), 'id', 'name');

Unfortunately this compares the ids in the database with just the first element of an array.

Suggestions?

jeesus
  • 469
  • 1
  • 8
  • 27

2 Answers2

4

Try to use not in instead of <>

-1

You can try following code example,

$arr = [16,14,1,13];
$items = ArrayHelper::map(User::find()->where(['id'=>$arr])->all(), 'id', 'name');

It works for me.

BDL
  • 21,052
  • 22
  • 49
  • 55
Monika
  • 1
  • 2