當我試圖將值添加到一個數組,它只是輸出數組對我來說,陣列功能輸出沒有
function getAllRoles($format='ids')
{
$format = strtolower($format);
$query = $this->db->prepare("SELECT * FROM roles");
$query->execute();
$resp = array();
foreach ($query as $row){
if ($format == 'full'){
$resp[] = array("ID"=>$row['ID'],"Name"=>$row['roleName']);
}else{
$resp[] = $row['ID'];
}
}
return $resp;
}
爲了讓我輸入數組,
echo "<br>getAllRoles: ".$Secure->getAllRoles("full");
不'echo'打印數組後必須使用'的print_r($陣列)'或'var_dump($ array)' – Salim