When I use PHP to do a simple query on a MySQL database, the object being returned holds duplicate values.
This is the PHP code where I query the database:
$query = 'SELECT * FROM names';
$result = mysqli_query($connection, $query);
$data = array();
while ($row = mysqli_fetch_array($result)) {
array_push($data, $row);
}
echo json_encode($data);
The returning JSON object (being outputted by the Chrome console through Javascript) is as follows:
[{"0": "1", "id": "1", "1": "Jeff", "name": "Jeff"},
{"0": "2", "id": "2", "1": "Andrew", "name": "Andrew"}]
Each value is listed twice: once as its correct column name and once as its column name's index. Does anyone know why this is happening?