Created
February 21, 2014 09:57
-
-
Save LiamChapman/9131649 to your computer and use it in GitHub Desktop.
Small shortand function for reading and encoding JSON in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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