I want the result for the json_encode()
as an array for example this:
[
{
"url":"http://localhost/.....",
"name":"abc"
},
{
"url":"http://localhost/.....",
"name":"xyz"
},
]
But I'm getting the result as an object as this :
{"images":[{"url":"http:\/\/192.168.0.100\/1.JPG","name":"abc"},{"url":"http:\/\/192.168.0.100\/2.JPG","name":"xyz"}]}
php code:
<?php
//Importing dbdetails file
require_once 'dbDetails.php';
//connection to database
$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect...');
//sql query to fetch all images
$sql = "SELECT * FROM images";
//getting images
$result = mysqli_query($con,$sql);
//response array
$response = array();
$response['images'] = array();
//traversing through all the rows
while($row = mysqli_fetch_array($result)){
$temp = array();
$temp['url']=$row['url'];
$temp['name']=$row['name'];
array_push($response['images'],$temp);
}
//displaying the response
echo json_encode($response);
I have tried using array_values as this:
echo json_encode(array_values($response));
But it results in an html code appended before the json string...