Generate Address String from Array / Object


/ Published in: PHP
Save to your folder(s)

Useful when used with the google map directions function http://snipplr.com/view/15530/php-create-google-map-directions-link/


Copy this code and paste it in your HTML
  1. function getAddress($dbObject) {
  2. $keys = array('address1', 'city', 'providence', 'postal_code');
  3. $values = array();
  4.  
  5. foreach($keys as $key)
  6. if(!empty($dbObject->$key))
  7. $values[] = $dbObject->$key;
  8.  
  9. return implode(' ', $values);
  10. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.