當我使用此代碼:流明@的foreach無效參數
$body=$request->all();
$contacts = json_decode($request->get('contacts'), true);
$user_contacts = array_flatten($this->_model->scan_contacts($this->_user->user_id, $contacts));
$nonsync_contacts = array();
foreach ($contacts as $contact) {
if (!in_array($contact["mobile"], $user_contacts)) {
$nonsync_contacts[] = $contact;
}
}
我收到此錯誤信息:
ErrorException in Arr.php line 493:
Invalid argument supplied for foreach()
如何避免這個錯誤?
顯示此print_r的輸出($ contacts) – Exprator
我確定$ contacts不是數組或它可能爲空 –