0
迴應我寫的:獲得來自陣列
$app->get('/tasks', 'authenticate', function() {
global $user_id;
$response = array();
$db = new DbHandler();
// fetching all user tasks
$result = $db->getAllUserTasks($user_id);
$response["error"] = false;
$response["tasks"] = array();
// looping through result and preparing tasks array
$response["error"] = false;
$response["id"] = $result["id"];
$response["task"] = $result["task"];
$response["status"] = $result["status"];
$response["createdAt"] = $result["created_at"];
echoRespnse(200, $response);
});
但是這個代碼,我只得到第一個結果[0] ...
{
error: false
tasks: [0]
id: 2
task: "Create something"
status: 0
createdAt: "2014-12-01 01:58:42"
}
如何讓同時在結果循環獲取所有數據從結果?
您使用的是什麼框架? – 2014-12-01 17:49:58
苗條的框架... – LaraBeginer 2014-12-01 17:50:58
你沒有循環任何東西。你應該傳入$ user_id而不是使用全局。 – 2014-12-01 17:51:50