dll*_*ire 11 php mysql arrays string implode
在过去的1 1/2天里,我一直试图将16行id存储到一个字符串中,并用逗号分隔每个id.我得到的数组来自MySQL.我得到的错误是
implode()函数:传递无效参数
$str=array();
$string="";
while($row = mysql_fetch_row($result))
{
$user_id=$row;
$str=$user_id;
foreach($str as $p=>$v){
comma($v);
}
}
function comma($v){
$string= implode(",",$v); echo $string;
}
Run Code Online (Sandbox Code Playgroud)
huy*_*itw 14
尝试这样的事情:
$ids = array();
while ($row = mysql_fetch_assoc($result))
{
$ids[] = $row["UserID"];
}
echo implode(", ", $ids);
Run Code Online (Sandbox Code Playgroud)
替换"UserID"为表中id的列名.
所以:首先构建数组,接下来将数组内部转换为字符串.