Skip to content

Instantly share code, notes, and snippets.

@mouyong
Last active June 25, 2017 04:28
Show Gist options
  • Save mouyong/551c252cfa766d3c0c822b2950be43e1 to your computer and use it in GitHub Desktop.
Save mouyong/551c252cfa766d3c0c822b2950be43e1 to your computer and use it in GitHub Desktop.
转换 Ajax 响应的 json
function json($status, $data = null, $message = 'success')
{
if (is_null($data)) {
$data = ['status' => $status, 'message' => $message];
} elseif (is_string($data)) {
$data = ['status' => $status, 'message' => $data];
} else {
$data = ['status' => $status, 'message' => $message, 'data' => $data];
}
return json_encode($data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment