Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to the implode the userIDs in the $users_in_range array the problem is it is iploding miles instead of userid

<?PHP
$users_in_range = users_in_range($lat, $long, 500, true); 

// implode users into mysql friendly list
$comma_separated = implode(",", $users_in_range);
echo $comma_separated;

// this is just for output while debugging
foreach ($users_in_range as $userid => $miles_away) {
    echo "UserID=<b>$userid</b> is <b>$miles_away</b> miles away from me.<br />";
}
?>
share|improve this question
    
How does $users_in_range array looks like? –  RaYell Jul 25 '09 at 7:46

2 Answers 2

up vote 4 down vote accepted

The userid is the key of the array, so you need to do:

$comma_separated = implode(",", array_keys($users_in_range));
share|improve this answer
    
bah, beaten by seconds again –  iAn Jul 25 '09 at 7:47
    
thanks, curious is this bad on performance? Would I be better off possibly reversing the order the array is created, like switch the key? If I made miles the key and userid a value, would I be able to sort by the miles key? –  jasondavis Jul 25 '09 at 7:52
    
The performance should be fine. You could switch it around and sort with ksort, but you'd have a problem if two users were the same distance away - I'd stick with what you have there. –  Greg Jul 25 '09 at 8:22

try :

$comma_separated = implode(',', array_keys($users_in_range));
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.