I have two variables from two different SQL queries that I want to put in to one JSON Array (i.e $hometown and $topcat). I am trying to hardcode it but not sure how it’s suppose to look.
print(json_encode('{"hometown":"' . $hometown .'", "category":"'. $topcat .'"}'));
My output is this:
{\"hometown\":\"Seattle, WA\", \"category\":\"Movies\"}"
Not sure where the slashes are coming from (I suppose I can to do stripslashes?) and it seems I need to add ‘[‘ and ‘]’ as well? What is the proper formatting for this?
json_encode()takes your array or object, it doesn’t accept strings that are already JSON encoded. It can be done like this:Outputs