Cast it as int
return [
'code' => (int) $code,
'value' => $record->description,
];
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am using below code to get status output :
if (! function_exists('status')) {
function status($code) {
$record = Status::getInstance(intval($code));
return [
'code' => $code,
'value' => $record->description,
];
}
}
output:
"status": {
"code": 2,
"value": "Active"
}
but sometimes i get output as:
"status": {
"code": "2",
"value": "Active"
}
if you see the code value in both the output, one is int as originally intended. Second one is a String value. Why is this happening ? how to stop this?
Cast it as int
return [
'code' => (int) $code,
'value' => $record->description,
];
Please or to participate in this conversation.