Leo505 Leo505 - 1 year ago 73
JSON Question

PHP index array for JSON

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) ) {
$row['children']= 'true';
$data[] = $row;
echo json_encode( $data);



When i need...


How would i go about removing the qoutes or inserting it correctly first.??

Answer Source

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);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download