我得到的一組數據從一個MySQL數據庫:in_array()PHP返回false全面,總是
Array (
[0] => Array ([upload_status] => 0)
[1] => Array ([upload_status] => 0)
[2] => Array ([upload_status] => 0)
[3] => Array ([upload_status] => 0)
[4] => Array ([upload_status] => 0)
[5] => Array ([upload_status] => 0)
[6] => Array ([upload_status] => 0)
[7] => Array ([upload_status] => 1)
[8] => Array ([upload_status] => 0)
[9] => Array ([upload_status] => 0)
[10] => Array ([upload_status] => 0)
[11] => Array ([upload_status] => 1)
[12] => Array ([upload_status] => 1)
[13] => Array ([upload_status] => 1)
)
我要檢查是否存在數組中0
。
我正在使用此代碼,但in_array()返回false,儘管事實上我可以看到上述數組中的零。
$query = $this
->db
->select('upload_status')
->where('lab_ref_no',$labref)
->get('sample_issuance')
->result_array();
print_r($query);
if (in_array('1', $query)) {
echo 'true';
} else {
echo'false';
}
你有一個數組數組。你正在尋找一個字符串。基本上,你做錯了。你需要爲你的字符串檢查每個子數組,而不是包裝它們。 –