Reputation: 107
Looking for some help.. Don't know the best approach to this issue... I'm pushing a new reference onto an array but the "true" value is being inserted with quotes, which fails my json format.
while( $row = mysqli_fetch_assoc($res) ) {
if($row['id']=="2"){
$row['children']= 'true';
}
$data[] = $row;
}
echo json_encode( $data);
Outputs
[{"id":"2","name":"john","text":"john","parent_id":"0","children":"true"}]
When i need...
{"id":"2","name":"john","text":"john","parent_id":"0","children":true}]
How would i go about removing the qoutes or inserting it correctly first.??
Upvotes: 1
Views: 45
Reputation: 2254
If you want the 'children' to be boolean then set it to boolean.
while( $row = mysqli_fetch_assoc($res) ) {
if($row['id']=="2"){
$row['children'] = true;
}
$data[] = $row;
}
echo json_encode( $data);
Upvotes: 1