Php 期望从以逗号分隔的数组中获得不同的输出
我想从数组中获取不同的值,并且这些值应该用逗号分隔 我喜欢英语、德语、法语,但我掌握的是英语、法语Php 期望从以逗号分隔的数组中获得不同的输出,php,Php,我想从数组中获取不同的值,并且这些值应该用逗号分隔 我喜欢英语、德语、法语,但我掌握的是英语、法语 <?php $cmd = mysql_query("select language from lang where dispname = 'Sk'"); while($out = mysql_fetch_array($cmd)) { $res = array_unique($out); $row = implode(",",$res);
<?php
$cmd = mysql_query("select language from lang where dispname = 'Sk'");
while($out = mysql_fetch_array($cmd))
{
$res = array_unique($out);
$row = implode(",",$res);
echo "$row";
}
?>
如果您看不出为什么代码没有达到预期效果,请在处理过程中转储数据。试试这个:-
<?php
$cmd = mysql_query("select language from lang where dispname = 'Sk'");
while($out = mysql_fetch_array($cmd))
{
echo '<pre>' . print_r($out,true) . '</pre>';
$res = array_unique($out);
echo '<pre>' . print_r($res,true) . '</pre>';
$row = implode(",",$res);
echo $row;
}
?>
我想知道这段代码是否真的有效……正如我已经解释过的,这段代码返回的值不带逗号,但我希望这些值用逗号分隔,所以如果你能帮助解决这个问题,它应该会告诉你可能出了什么问题。如果你不能解决这个问题,请通过编辑你的问题发布结果。