Reputation: 1041
I have send array from view to my controller using ajax, then I want compare it with my model. But I don't know how to get array when use ActiveQuery
like this:
$riderAll = Riders::find()->select('user_id')->asArray()->all();
$tableData = array_diff($tableData, $riderAll);
Getting error array to string conversion. Tell me what's wrong in $riderAll
? please
Upvotes: 2
Views: 1648
Reputation: 4160
Instead of using all()
in activeQuery ..
You have to use column()
which will give 1-D array so that you can easily apply array_diff()
Try this code ..
$riderAll = Riders::find()->select ('user_id')->asArray()->column();
$tableData = array_diff($tableData,$riderAll);
In above you are using all()
which will output 2-D array so array_dff()
not be applicable. Ask if other Problem occur..
Upvotes: 5
Reputation: 1041
I have solution I'm create some function to make same structure:
function getArr($array, $key) {
$return = array();
foreach($array as $row) {
$return[] = $row[$key];
}
return $return;
}
how to use: $arr = $this->getArr($riderAll, 'rider_id');
then $tableData3 = array_diff($tableData, $arr);
Upvotes: 1
Reputation: 133360
Try usinge array for select
$riderAll = Riders::find()->select(['user_id'])->asArray()->all();
$tableData = array_diff($tableData, $riderAll);
Upvotes: 1