分為兩步:
第一步,找出數據庫中所有表名,表名得到的是二維數組。
第二步,判斷表名是否存在二維數組中
下面就貼我的代碼咯。
$table_name =‘table’; $juge = $handle->createCommand("show tables ")->queryAll();
//下面的deep_in_array()方法是自己寫的方法,判斷是否存在值是否存在二維數組中,yii2中調用本類方法,可以去掉action $cun = $this->deep_in_array($table_name,$juge); if(!$cun){ echo json_encode("nodata"); return; }
//判斷二維數組是否存在值 public function deep_in_array($value, $array) { foreach($array as $item) { if(!is_array($item)) { if ($item == $value) { return true; } else { continue; } } if(in_array($value, $item)) { return true; } else if($this->deep_in_array($value, $item)) { return true; } } return false; }