我下面就tutplus this tutorial,我碰到这个代码片段传来:这是一个PHP关联数组吗?
//check if the action exists in the controller. if not, throw an exception.
if(method_exists($controller, $action) === false) {
throw new Exception('Action is invalid.');
}
//execute the action
$result['data'] = $controller->$action();
$result['success'] = true;
} catch(Exception $e) {
//catch any exceptions and report the problem
$result = array();
$result['success'] = false;
$result['errormsg'] = $e->getMessage();
}
//echo the result of the API call
echo json_encode($result);
exit();
我在PHP初学者,我在想,如果result
是一个关联数组?有人可以证实这一点吗?如何才能说明关联数组和非关联数组之间的区别?
是。因为您要为数组中的每个元素提供一个键名。 – Drumbeg
它是一个关联数组。它将键值“sucess”,“errormsg”与值相关联。 –
我建议阅读文档。 http://uk3.php.net/manual/en/language.types.array.php – Drumbeg