vlowe Posted October 23, 2011 Share Posted October 23, 2011 hi i have an array that returns the longitude, latitude and timestamp of multiple users. then i use a for each loop to echo the details to add markers to google maps. the problem is that if one of the users has no gps position i dont want to include it it my foreach loop. foreach($positions as $name => $status) { echo 'add(jQuery(this), number += 1, "' . $name . '", "map_post.php?n=' . $name . '&u=' . $status['user_id']. '", "' . date("d-m-Y @ h:i:s",$status['timestamp']) . '", "' . $status['latitude'] . '", "' . $status['longitude'] . '", "' . $status['user_id']. '");'; } how can i get the foreach to ignore the users with no data? Quote Link to comment https://forums.phpfreaks.com/topic/249626-how-can-i-unset-this-array-value/ Share on other sites More sharing options...
ignace Posted October 23, 2011 Share Posted October 23, 2011 how can i get the foreach to ignore the users with no data? No offense, but if you can't answer that question you should consider looking for another job. if ($status['latitude'] && $status['longitude']) { Will skip the users with no valid latitude & longitude although you probably should put this in your query. WHERE latitude > 0 && longitude > 0 Which negates the need for an if statement in your foreach. Quote Link to comment https://forums.phpfreaks.com/topic/249626-how-can-i-unset-this-array-value/#findComment-1281499 Share on other sites More sharing options...
vlowe Posted October 23, 2011 Author Share Posted October 23, 2011 LOL seems obvious now, thank for that. im not selecting from database im getting data from soap. Quote Link to comment https://forums.phpfreaks.com/topic/249626-how-can-i-unset-this-array-value/#findComment-1281501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.