str_getcsv到一个关联数组?

时间:2013-03-05 22:10:24

标签: php multidimensional-array

我有以下代码生成一个非常好的索引数组 -

<?php
// reads csv file and returns an array of rows
function read_csv($filename){
$rows = array();
foreach (file($filename, FILE_IGNORE_NEW_LINES) as $line){
$rows[] = str_getcsv($line, $delimiter = '; ', $escape = '\''); 
} 
return $rows;
}        
?>

输出看起来像 -

Array
        (
            [0] => Array
                (
                [0] => value
                [1] => value
                [2] => value
                [3] => value
                [4] => value
                [5] => value
                [6] => value
                [7] => value
                [8] => value
                [9] => value
                [10] => value
                [11] => value
                [12] => value
                [13] => value
                [14] => value
                [15] => value
                [16] => value
                [17] => value
                [18] => value
                [19] => value
                [20] => value
)

是否可以将内部数组的指针设置为如下所示 -

Array
        (
        [0] => Array
            (
                [label 1] => value
                [label 1] => value
                [label 2] => value
                [label 3] => value
                [label 4] => value
                [label 5] => value
                [label 6] => value
                [label 7] => value
                [label 8] => value
                [label 9] => value
                [label 10] => value
                [label 11] => value
                [label 12] => value
                [label 13] => value
                [label 14] => value
                [label 15] => value
                [label 16] => value
                [label 17] => value
                [label 18] => value
                [label 19] => value
                [label 20] => value
)

我不知道如何让str_getcsv这样做。也许在str_getcsv函数之前定义数组的元素(不知道怎么做)?寻找类似于关联数组的东西...

0 个答案:

没有答案
相关问题