Skip to content

Instantly share code, notes, and snippets.

@taichunmin
Created April 11, 2016 03:02
Show Gist options
  • Save taichunmin/5464d5fbb60bd4d39d6db5d2ab5b98cd to your computer and use it in GitHub Desktop.
Save taichunmin/5464d5fbb60bd4d39d6db5d2ab5b98cd to your computer and use it in GitHub Desktop.
<?php
if(!function_exists('encode_json')) {
function encode_json( $var ) {
static $options = null;
if (is_null($options)) {
$options = 0;
if (version_compare(PHP_VERSION, '5.3.3') >= 0)
$options |= JSON_NUMERIC_CHECK;
if (version_compare(PHP_VERSION, '5.4.0') >= 0)
$options |= JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE;
}
return json_encode($var, $options);
}
}
$response = [
[
'0' => '不分區',
'north' => '北',
'east' => '東',
'west' => '西',
'middle' => '中',
'south' => '南',
],
];
echo encode_json($response).PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment