- is_numeric: documentation ( source)
- json_encode: documentation ( source)
- array_walk_recursive: documentation ( source)
<?php
$array = [
'code' => 200,
'results' => [
'id' => 1
],
'a' => [
[
'b' => [
4,
null,
false
]
]
]
];
array_walk_recursive(
$array,
function(&$v) {
if (is_numeric($v)) {
$v = strval($v);
}
}
);
echo json_encode($array);