Essentially I have the following script with the following response:
<?php
header('Content-Type: application/json');
$stmt = $pdo->prepare('
SELECT
`tablelist`.`id`,
`tablelist`.`content`
FROM `tablelist `
');
$stmt->execute([
]);
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
$rowcount = $stmt->rowCount();
if ($rowcount < 1) {
$response["error"] = TRUE;
echo json_encode($response);
}else{
echo json_encode($row);
}
?>
Current Response:
[
{
"id": 1,
"content": "Reason 1"
},
{
"id": 2,
"content": "Reason 2"
},
{
"id": 3,
"content": "Reason 3"
},
{
"id": 4,
"content": "Reason 4"
}
]
I would instead like to present this array as the following (no square brackets):
{
"error": false,
"content": {
"1": "Reason 1",
"2": "Reason 2",
"3": "Reason 3",
"4": "Reason 4"
}
I know I need to do the following:
$response["error"] = FALSE;
$response["content"][$row[id]] = $row[content];
But using this method I am not getting any values from the array.
How can present the values from the array the way?