Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
funcion para convertir array o object to json
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