Jump to content


**solved** Array Help

  • Please log in to reply
4 replies to this topic

#1 kalinkap

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 24 March 2006 - 07:49 PM

First off, I'm new to PHP and trying to store values returned from a call to another site. I get the results in the following form:
[ResultSet] => Array
[Result] => Array
[precision] => address
[Latitude] => 42.306295
[Longitude] => -83.244328
[Address] => 22000 MICHIGAN AVE
[City] => DEARBORN
[State] => MI
[Zip] => 48124-2353
[Country] => US



Now I would like to pull the values stored for Latitude and Longitude for comparison to other values I have to calculate distance between two points. I've looked all over and just can't seem to figure out how to access the values. I feel like an idiot because I'm sure there is a simple solution but have yet to be able to get it working. I can also get the serialized data if thats easier to work with.

Please help! I'm at a standstill. Thanks in advance for any help that may be provided!

#2 holowugz

  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 24 March 2006 - 07:56 PM

You can access an assosiative array as such


I am fairnly new to PHP aswell i am afriad i cant tell from what you posted what the array name is but what ever it is that should work ok.

#3 kalinkap

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 24 March 2006 - 08:07 PM

here is the code where I unserialize and pull the array contents to be displayed:

$phpobj2 = unserialize($response);

echo '<pre>';
$temptest2 = print_r($phpobj2, true);

I tried

printf("st_lat: %d ", $st_lat);

and that didn't work, the displayed value is '0'. If i try displaying it as a string it comes back as 'A'. Am I calling the right array name?

Thanks for the quick response!

Luke do you have AOL IM? my name is PKatMSU if you are online

#4 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 24 March 2006 - 08:35 PM

Assuming the array you posted is called $data

$latitude = $data['ResultSet']['Result']['Latitude'];

$longitude = $data['ResultSet']['Result']['Longitude'];

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 kalinkap

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 24 March 2006 - 08:48 PM

Thanks for your help. That did it. I knew it was something stupid I was doing... For anyone who looks at this for help, here is the code that is the solution:

$st_lat = $phpobj2['ResultSet']['Result']['Latitude'];
$st_long = $phpobj2['ResultSet']['Result']['Longitude'];

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users