PHP - Multidimensional array to CSV

后端 未结 3 1899
情深已故
情深已故 2020-12-12 03:20

I currently have coded a way to turn a multidimensional array to comma separated values (I\'m using pipes instead of commas for ease of debugging). The problem is, I know th

3条回答
  •  北海茫月
    2020-12-12 03:38

    I didn't check it, so in case it doesn't work it should be corrected.

    function readarray($from_array, $addr = array()) {
        global $output;
        foreach ($from_array as $key => $value) {
            if (is_Array($value) && count($value) > 0) {
                $addr[] = $key;
                readarray($value, $addr);
            } else {
                $output[] = implode('||', $addr) . $value;
            }
        }
    
    }
    
    
    $output = array();
    foreach ($my_array as $key=>$value){
    readarray($value); 
    }
    

    // improved to get separate arrays of the root of initial array

提交回复
热议问题