-1

Currently trying this:

unset($jsonArr-[$json]);

but I get this error: Parse error: syntax error, unexpected '-', expecting ',' or ')'

This has to be simple to do. I've been searching for an answer to this for hours. I think I've tried everything listed on this site. I'm pulling lat and lng from mapquest and I need to clear the array to do the next record.

$json = file_get_contents('http://www.mapquestapi.com/geocoding/v1/address?key=MYKEY&Format=json&inFormat=json&json={location:{street:%22$address%22},options:{thumbMaps:false,maxResults:1}}');
$jsonArr = json_decode($json);

$lat = $jsonArr->results[0]->locations[0]->latLng->lat;
$lon = $jsonArr->results[0]->locations[0]->latLng->lng;

Any help would be greatly appreciated.

UPDATE - Totally not the array not clearing, it was the variable in the address.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • It's not clear what you're trying to do. Why won't `unset($jsonArr);` do what you want? –  May 05 '14 at 20:37
  • No matter what address I enter I get the same lat and lon, through a process of elimination it looks like $jsonArr is not clearing when I run it. – user3605757 May 05 '14 at 20:51
  • Your problem is somewhere else. `$jsonArr` will be set to something by `json_decode()`, even if the parsing process fails. It's more likely that your call to the API is always returning the same values. You should use `var_dump($json)` immediately after you request the data to make sure you're getting what you think you are. –  May 05 '14 at 21:16

1 Answers1

0

If you want to clear the array you simply

unset($jsonArr);
Kivylius
  • 6,357
  • 11
  • 44
  • 71