PHP爆阵帮助(php imploding array help)

2019-10-17 03:02发布

我想给破灭了用户ID的$ users_in_range数组中的问题是,它是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 />";
}
?>

Answer 1:

该用户ID是在阵列的关键,所以你需要做的:

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


Answer 2:

尝试:

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


文章来源: php imploding array help