php - Converting nested JSON array -


i have php function builds json array via

$jsonarray= array(); ($i=0; $i<$dircount; $i++){   $query = sprintf("select * tour filename= '../%s/%s'", $imagedirectory, $dirarrays[$i]);   $result = mysqli_query($link, $query);    if (mysqli_num_rows($result) == 1){     $row = mysqli_fetch_row($result);     $jsonarray[]= array('filename'=>$dirarrays[$i], 'location'=>$row[4], 'latitude'=>$row[2], 'longitude'=>$row[3], 'heading'=> $row[5]);   }  } 

and returns upon execution via ajax query.

however, shown in firebug

[   0 : object{ 'filename' : , 'location': , 'latitude': , 'longitude: },   1 : object{ 'filename' : , 'location': , 'latitude': , 'longitude: },  ] 

and on

how can convert index locations location value instead? have in mind is

'start' : object{ 'filename' : , 'location': , 'latitude': , 'longitude: }, 'testlab' : { 'filename' : , 'location': , 'latitude': , 'longitude: } 

the reason behind have function creates object data fields upon match location field.

function builddata(input){   (var i=0; i<data.length; i++){     if (data[i].location == input)       //create , return object using data[i] fields   }  } 

i'd rid of loop , rely on conditional like

function builddata(input){   if (data[input]){     //same object creation , return   } } 

how done?

instead of pushing each element of array ($jsonarray[] = ...), assign relevant key ($jsonarray[$somekey] = ...).


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -