Skip to content

Instantly share code, notes, and snippets.

@LiamChapman
Created February 21, 2014 09:57
Show Gist options
  • Select an option

  • Save LiamChapman/9131649 to your computer and use it in GitHub Desktop.

Select an option

Save LiamChapman/9131649 to your computer and use it in GitHub Desktop.
Small shortand function for reading and encoding JSON in php
<?php
if (!function_exists('json')) {
function json ($data) {
// if string we return as array
if (is_string($data)) {
return json_decode($data, true);
// if array or object we encode it
} else if (is_array($data) || is_object($data)) {
return json_encode($data);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment