Last active
August 28, 2021 11:02
-
-
Save HazemNoor/8cf2b6f7deea0eef68b826e9abb39afe to your computer and use it in GitHub Desktop.
Function to check if a string is valid json string and return data if valid or false otherwise
This file contains 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 | |
/** | |
* Check if a string is valid json string and return data if valid or false otherwise | |
* | |
* @params Same as json_decode args | |
* | |
* @return false|mixed | |
*/ | |
function json_get() | |
{ | |
$data = call_user_func_array('json_decode', func_get_args()); | |
return (is_string(func_get_arg(0)) && json_last_error() == JSON_ERROR_NONE) ? $data : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment