来自嵌套数组的 CSV

CSV From Nested array

使用高级 Medoo 时 select 像这样:

$medoo->query('SQL Goes HERE')->fetchAll();

结果按以下结构返回:

Array ( 
    [0] => Array ( 
        [Column 0 name] => "VALUE OF Record 0, Column 0" 
        [0] => "VALUE OF Record 0, Column 0" 
        [Column 1 name] => "VALUE OF Record 0, Column 1" 
        [1] => "VALUE OF Record 0, Column 1"
        ...
        ...
        [Column 99 name] => "VALUE OF Record 0, Column 99" 
        [99] => "VALUE OF Record 0, Column 99"
        ) 
    [1] => Array ( 
        [Column 0 name] => "VALUE OF Record 1, Column 0" 
        [0] => "VALUE OF Record 1, Column 0" 
        [Column 1 name] => "VALUE OF Record 1, Column 1" 
        [1] => "VALUE OF Record 1, Column 1"
        ...
        ...
        [Column 99 name] => "VALUE OF Record 1, Column 99" 
        [99] => "VALUE OF Record 1, Column 99"
        )
    ...
    ...
    ... 
    [99] => Array ( 
        [Column 0 name] => "VALUE OF Record 99, Column 0" 
        [0] => "VALUE OF Record 99, Column 0" 
        [Column 1 name] => "VALUE OF Record 99, Column 1" 
        [1] => "VALUE OF Record 99, Column 1"
        ...
        ...
        [Column 99 name] => "VALUE OF Record 99, Column 99" 
        [99] => "VALUE OF Record 99, Column 99"
        )
)

出于某种原因,每个数组都有一个关联键和一个索引键值对,而不是 100% 为什么他们以这种方式构建它。关于如何删除所有索引结果并仅保留关联数组的任何建议?

您可能需要这些内容。这是假设您概述的数据类型是准确的

$columns = array(array());
foreach ($arr[0] as $key => $value) {
    if (!is_int($key)) {        
        $columns[0][] = $value;
    }
}

$rows = array();
foreach ($arr as $results) {
    $thisRow = array();
    foreach ($results as $key => $value) {
        if (is_int($key)) {
            $thisRow[] = $value;
        }
    }
    $rows[] = $thisRow;
}

$output = array_merge($columns, $rows);

fetchAll需要正确填写:

$medoo->query('Query String')->fetchAll(PDO::FETCH_ASSOC);