Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 期望从以逗号分隔的数组中获得不同的输出_Php - Fatal编程技术网

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

我想知道这段代码是否真的有效……正如我已经解释过的,这段代码返回的值不带逗号,但我希望这些值用逗号分隔,所以如果你能帮助解决这个问题,它应该会告诉你可能出了什么问题。如果你不能解决这个问题,请通过编辑你的问题发布结果。