php - Replace array keys -
i have array json example .i'm trying replace numeric key ..."conn":{"1":{"... string key such "node".
for example want create this:
{ "level": [ { "main": "472321514", "main_lat": "39.1057579", "main_lon": "26.5451331", "conn": { "node": { "id": "599416249", "coords": { "lat": "39.1055889", "lon": "26.5452403" }, "distance": 0.0209442235276 },...
before json encoding script is:
foreach ($ways $w){ $nd=$w->nd; foreach ($nd $w2){ $nodes_array[]=(string)$w2->attributes()->ref; } for($ww=0;$ww<count($nodes_array);$ww++){ $nodes_array2[$bb]['main'] = $nodes_array[$ww]; for($gg=0;$gg<count($node_content);$gg++){ if($node_content[$gg]['id']==$nodes_array2[$bb]['main']){ $nodes_array2[$bb]['main_lat']= $node_content[$gg]['lat']; $nodes_array2[$bb]['main_lon']= $node_content[$gg]['lon']; } } $nodes_array2[$bb]['conn'] = array_diff($nodes_array, array($nodes_array[$ww])); for($cc=0;$cc<count($nodes_array2[$bb]['conn']);$cc++){ for($gg=0;$gg<count($node_content);$gg++){ if($node_content[$gg]['id']==$nodes_array2[$bb]['conn'][$cc]){ $nodes_array2[$bb]['conn'][$cc]=array( 'id'=>$node_content[$gg]['id'], 'coords'=>array( 'lat'=>$node_content[$gg]['lat'], 'lon'=>$node_content[$gg]['lon'], ), 'distance'=>distance($nodes_array2[$bb]['main_lat'],$nodes_array2[$bb]['main_lon'],$node_content[$gg]['lat'],$node_content[$gg]['lon'],"k"), ); } } } $bb++; } unset($nodes_array); }
Comments
Post a Comment