php imploding array help

2019-08-05 08:23发布

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 />";
}
?>

2条回答
手持菜刀,她持情操
2楼-- · 2019-08-05 08:57

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

$comma_separated = implode(",", array_keys($users_in_range));
查看更多
一纸荒年 Trace。
3楼-- · 2019-08-05 09:07

try :

$comma_separated = implode(',', array_keys($users_in_range));
查看更多
登录 后发表回答