php imploding array help

牧云@^-^@ 提交于 2019-12-11 12:30:50

问题


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

回答1:


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

$comma_separated = implode(",", array_keys($users_in_range));



回答2:


try :

$comma_separated = implode(',', array_keys($users_in_range));


来源:https://stackoverflow.com/questions/1181516/php-imploding-array-help

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!