duanao2585 2015-02-20 01:59
浏览 17

将两级多维数组保存到php中的csv文件中

I have an array that when printed with print_r looks like this:

Array(
[0] => Color
[Color] => Array
    (
        [0] => Red
        [1] => white
        [2] => Bleu
     )
[1] => size
[size] => Array
    (
        [0] => Small 
        [1] => Med 
        [2] => Large
     )
)

I am trying to dump it to a csv file that should look like this when finished:

Color: Red, White, Blue

size: Small, "1-1/2 Inch", "8 inch"

The code below gets part of the job done but I am having trouble getting the array keys to print out at the beginning of each line in the csv file. Thanks.

<?php

print_r($mf_url_array);

$fp = fopen('file.csv', 'w');
fputcsv($fp, array_keys($mf_url_array));
foreach ($mf_url_array as $fields) {
    if(!empty($fields) and is_array($fields)){
    fputcsv($fp, $fields);
    }
}

fclose($fp);
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭