I am trying to create an array in php that will be parsed as json in javascript via ajax call. I noticed that the first index of an array instantiated with $empty = array() returns as {"0":[{..values here..}], "success":true}. Ideally I would access it using reply.data and reply.success. The reply. success works, but I can't seem to find how to create an array without a 0 as the first index.
My php side code:
$result = array();
$record = array();
$resp = mysqli_query($this->conn, $sql);
if(mysqli_num_rows($resp)>0){
while($row = mysqli_fetch_assoc($resp)){
$record = array();
foreach($row as $key => $val){
$record[$key] = $val;
}
array_push($result,$record);
unset($record);
}
//return json_encode($result, JSON_PRETTY_PRINT);
return $result;
When I access it within javascript
success: function(data){
data = JSON.parse(data);
if(data.success==true){ //able to access success with "data.success"
//there is an empty
$scope.conn = "connecting to room";
console.log(data.data.room_id); //does not work because index is 0
console.log(JSON.stringify(data));
What it returns
{"0":[{"room_id":"20","host_id":"","resp_id":"","offer":"","answer":"","status":"0"}],"success":true}