如果我有一个像这样的数组:

Array ( [0] => abcdef )
Array ( [0] => abcdef [1] => abcdef )
Array ( [0] => abcdef [1] => abcdef [2] => abcdef )
Array ( [0] => abcdef [1] => qwerty )


并想要创建一个逗号分隔的列表,例如:

abcdef, abcdef, abcdef, abcdef, abcdef, abcdef, abcdef, qwerty


我该怎么做?

当我尝试像这样分解数组时:

while($row = mysql_fetch_array($search)){
    $row2 = $row['scholarshipid'];
    $newarray = unserialize($row2);
    $unique_array = array_unique($newarray, SORT_REGULAR);
    $commaList = implode(', ', $unique_array);
    echo "$commaList";
    //print_r($newarray);
}

$commaList = implode(', ', $unique_array);


我得到:

abcdefabcdefabcdefabcdef, qwerty

最佳答案

comments中可以看出,您显示给我们的输出来自循环。因此,您首先必须将每次迭代中的所有数组收集到1个变量中,然后可以将其内爆,例如

$ result = [];

while($ row = mysql_fetch_array($ search)){
    $ row2 = $ row ['cholarshipid'];
    $ newarray =反序列化($ row2);
    $ unique_array = array_unique($ newarray,SORT_REGULAR);
    $ result = array_merge($ result,$ unique_array);
}

echo implode(“,”,$ result);

10-08 16:31