The method accepts:
- a scalar value (integer or string): query by a single primary key value and return an array containing the
corresponding record (or an empty array if not found).
- a non-associative array: query by a list of primary key values and return the
corresponding records (or an empty array if none was found).
Note that an empty condition will result in an empty result as it will be interpreted as a search for
primary keys and not an empty WHERE condition.
- an associative array of name-value pairs: query by a set of attribute values and return an array of records
matching all of them (or an empty array if none was found). Note that ['id' => 1, 2] is treated as
a non-associative array.
This method will automatically call the all() method and return an array of [[ActiveRecordInterface|ActiveRecord]]
instances. For example,
php
find the customers whose primary key value is 10
$customers = Customer::findAll(10);
the above code is equivalent to:
$customers = Customer::find()->where(['id' => 10])->all();
find the customers whose primary key value is 10, 11 or 12.
$customers = Customer::findAll([10, 11, 12]);
the above code is equivalent to:
$customers = Customer::find()->where(['id' => [10, 11, 12]])->all();
find customers whose age is 30 and whose status is 1
$customers = Customer::findAll(['age' => 30, 'status' => 1]);
the above code is equivalent to:
$customers = Customer::find()->where(['age' => 30, 'status' => 1])->all();