skip to Main Content

this is my code…

$resp = json_decode($resp_json, true);
return array($resp[0][‘lat’], $resp[0][‘lon’]);

this is my var_dump(json_decode($resp_json, true)); // vardump is below

///

array(1) { [0]=> array(15) { ["place_id"]=> int(308959017) ["licence"]=> string(70) "Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright" ["osm_type"]=> string(3) "way" ["osm_id"]=> int(570688234) ["lat"]=> string(10) "34.0722265" ["lon"]=> string(19) "-117.43345301493153" ["class"]=> string(7) "amenity" ["type"]=> string(8) "hospital" ["place_rank"]=> int(30) ["importance"]=> float(0.18764122278025944) ["addresstype"]=> string(7) "amenity" ["name"]=> string(40) "Kaiser Permanente Fontana Medical Center" ["display_name"]=> string(127) "Kaiser Permanente Fontana Medical Center, 9961, Sierra Avenue, Fontana, San Bernardino County, California, 92335, United States" ["address"]=> array(10) { ["amenity"]=> string(40) "Kaiser Permanente Fontana Medical Center" ["house_number"]=> string(4) "9961" ["road"]=> string(13) "Sierra Avenue" ["city"]=> string(7) "Fontana" ["county"]=> string(21) "San Bernardino County" ["state"]=> string(10) "California" ["ISO3166-2-lvl4"]=> string(5) "US-CA" ["postcode"]=> string(5) "92335" ["country"]=> string(13) "United States" ["country_code"]=> string(2) "us" } ["boundingbox"]=> array(4) { [0]=> string(10) "34.0705513" [1]=> string(10) "34.0738878" [2]=> string(12) "-117.4355221" [3]=> string(12) "-117.4294710" } } }

///

I am not getting any return values for the lat or lon array values. I see it there i just cant extract it. Please bare with me I am new to json and this is my first post.

I have tried many different approaches to output the array but still nothing.

2

Answers


  1. Chosen as BEST ANSWER

    I figured out the code does work. I didnt extract it right. I ended up just assigning each array to a variable like this and I now have the data.

    $don = array($resp[0]['lat']);
    $dom = array($resp[0]['lon']);
    
    echo $resp[0]['lat'];
    echo $resp[0]['lon'];
    

  2. For me everything is working. Could you please give us a little bit more of code?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search