yii2 where in的用法

//多个id放入数组中
     $idStr = [];
          foreach ($roleData as $key => $value){
              $idStr[] = $value['id'];
          }
          $roleEatlive = RoleEatlive::find()
            ->where(['in','role_id',$idStr])
            ->asArray()->all();

//也可以

    ->where([  
        'in', 'id', [1, 3, 5, 6]  
    ])  
//not in 我就不说了

    ->where([  
        'not in', 'id', [1, 2, 4, 3]  
    ])  
$obj_all = self::find()->where(['not in','id',array_column(self::find()->select('pid')->asArray()->all(), 'pid')])->all();

  

原文地址:https://www.cnblogs.com/llxpbbs/p/9268196.html