我試圖縮短我的代碼,我認爲使用數組是最好的方法。PHP:檢查數組是否全部爲真
此代碼是由非常多不同的查詢(mysqli的)像這樣的:
$a = $this->db->query("DELETE * FROM ....");
$b = $this->db->query("DELETE * FROM ....");
$c = $this->db->query("DELETE * FROM ....");
$d = $this->db->query("DELETE * FROM ....");
$e = $this->db->query("DELETE * FROM ....");
$f = $this->db->query("DELETE * FROM ....");
$g = $this->db->query("DELETE * FROM ....");
$h = $this->db->query("DELETE * FROM ....");
$i = $this->db->query("DELETE * FROM ....");
$j = $this->db->query("DELETE * FROM ....");
$k = $this->db->query("DELETE * FROM ....");
要查看該查詢正確執行我這樣做(因爲他們將返回真/假):
if($a && $b && $c && $d && $e && $f && $g && $h && $i && $j && $k){
//action
}
但每次我添加查詢我已經將它添加到if語句和它得到這麼久,我不知道,如果我把它與否時間... ...
所以,現在我正在考慮做什麼克這種使用數組:
$a[0] = $this->db->query("DELETE * FROM ....");
$a[1] = $this->db->query("DELETE * FROM ....");
$a[2] = $this->db->query("DELETE * FROM ....");
$a[3] = $this->db->query("DELETE * FROM ....");
$a[4] = $this->db->query("DELETE * FROM ....");
$a[5] = $this->db->query("DELETE * FROM ....");
$a[6] = $this->db->query("DELETE * FROM ....");
$a[7] = $this->db->query("DELETE * FROM ....");
$a[8] = $this->db->query("DELETE * FROM ....");
$a[9] = $this->db->query("DELETE * FROM ....");
$a[10] = $this->db->query("DELETE * FROM ....");
if($a === true){
//ok
}else{
//notok;
}
但這個代碼(if語句)不工作... 我在做什麼錯?
因此,如果查詢執行時假定'$ this-> db-> query()'返回true(或真值)是否正確? –
@EdCottrell對!將返回true/false。 –