Created
April 10, 2021 02:33
-
-
Save dario61081/c621a3b3e42401d6e1a30014398aa771 to your computer and use it in GitHub Desktop.
funcion para convertir array o object to json
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
function toJsonPDO($resultset) | |
{ | |
$t = gettype($resultset); | |
if ($t === 'object') { | |
return json_encode(get_object_vars($resultset), JSON_NUMERIC_CHECK); | |
} else if ($t === 'array' && sizeof($resultset) === 1) { | |
return json_encode($resultset[0], JSON_NUMERIC_CHECK); | |
} else if ($t === 'array' && sizeof($resultset) > 1) { | |
return json_encode($resultset, JSON_NUMERIC_CHECK); | |
} else { | |
return json_encode(new stdClass(),JSON_NUMERIC_CHECK); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment