php imploding数组帮助

时间:2009-07-25 07:43:06

标签: php arrays implode

我试图破坏$ users_in_range数组中的userIDs问题是它是iploding里程而不是用户ID

<?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 个答案:

答案 0 :(得分:4)

userid是数组的键,因此您需要执行以下操作:

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

答案 1 :(得分:1)

尝试:

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