PHP CSV以特定方式呈现数组

Or *_*ger 3 php csv arrays

我知道fgetcsv,但它并没有真正做我想要的.

我有以下csv文件:

productId,productName,productActive
1,test product,1
2,test product2,0
Run Code Online (Sandbox Code Playgroud)

我正在寻找能够创建如下所示数组的东西:

array (0)
    ['productId'] => 1
    ['productName'] => test product
    ['productActive'] => 1

array (1)
    ['productId'] => 2
    ['productName'] => test product2
    ['productActive'] => 0
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

cod*_*ict 7

// open the file.
if (($handle = fopen("in.csv", "r")) !== FALSE) {
        // read the column headers in an array.
        $head = fgetcsv($handle, 1000, ",");

        // read the actual data.
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {

                // create a new array with the elements in $head as keys
                // and elements in array $data as values.
                $combined = array_combine($head,$data);

                // print.
                var_dump($combined);
        }
        // done using the file..close it,
        fclose($handle);
}
Run Code Online (Sandbox Code Playgroud)

看见