I am trying to convert my data received from MySql into JSON, in following format -
[
{
"question": "This is a question",
"options": [
"Option which may contain double or single quoted text",
"Option 2",
"Option 3",
"Option 4"
]
}
]
My relevant PHP code, so far is -
<?php
$result = mysql_query("select * from test_table limit 5", $db);
$json_response = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$option_01 = $row['Option_1'];
$option_02 = $row['Option_2'];
$option_03 = $row['Option_3'];
$option_04 = $row['Option_4'];
$row_array['question'] = $row['Question'];
// I am unable to format Options ($option_01,$option_02,$option_03,$option_04) into desired Array as mentioned in starting
$row_array['options'] = "";
array_push($json_response,$row_array);
}
echo json_encode($json_response);
?>
But I am stuck on how to make array of option variables, received from MySql database?