Connor Bishop Connor Bishop - 1 year ago 62
JSON Question

Echoing JSON Data in php

Im trying to echo some JSON Data. The problem is the data contains variables but my code isn't putting the variables into the string.
Heres my code:

$status = $row['Status'];
$priority = $row['Priority'];
echo '{"status":"$status","priority":"$priority"}' ;


this php is echoing

{"status":"$status","priority":"$priority"}


when I need to echo

{"status":"Completed","priority":"High"}


for example. How can I fix this?

Answer Source

Just use json_encode function

echo json_encode($row);