Answer the question
In order to leave comments, you need to log in
Pass function to JSON in PHP?
Hey!
Serialize array in php:
$arr = array(
'id' => $a,
'name' => $b,
'value' => $c,
'fill' => "somefunction('".$d."')"
);
echo json_encode($arr);
[{
"id": "1",
"name": "123",
"value": 100,
"fill": somefunction('data')
}, {
"id": "2",
"name": "123",
"value": 50,
"fill": somefunction('data')
}]
[{
"id": "1",
"name": "123",
"value": 100,
"fill": "somefunction('data')"
}, {
"id": "2",
"name": "123",
"value": 50,
"fill": "somefunction('data')"
}]
Answer the question
In order to leave comments, you need to log in
so that json is shown like thisThis is not valid JSON, so yes, you need to write your own serialization to this non-standard format.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question