php array is outputting as Array


php array is outputting as Array

我是php新手,我的数组输出为数组。它们是一种将内爆的逗号分隔的字符串拉出其实际值的方法吗?

$result = $sql->query($query);
while($row = $result->fetch_row()) {
$rows[]=$row;
}
$result->close();
$sql->close();
$all = implode(',', $rows);
echo $all 
输出:

Array,Array,Array,Array

我使用

让它工作
 $result = $sql->query($query);
        $rows = array(); 
        while($row = $result->fetch_assoc()) {
            $rows[]=$row;
        }
        $result->close();
        $sql->close();
        $str = implode(',', array_map(function($el){ return $el['username']; }, $rows));
        echo $str;

您必须使用print_r($all)才能查看数组内容。