-1

I am having issue in exporting data in CSV file. When i pass "Static data" then it exported. But I want "Dynamically" i.e. user_name or user_lastname store my data. So, anyone can help me to get out from this.

My Dynamic array is showing in this format inside while loop:

print_r($arr);

    Array
    (
        [0] => Meck
    )
    Array
    (
        [0] => Bisk
    )
    ...


while ( $query->have_posts() ) : $query->the_post();    

        $user_name            = get_post_meta( get_the_ID(), 'glow_user_fname', true );
        $first                = $array = explode(' ', $user_name);
        $user_lastname        = get_post_meta( get_the_ID(), 'glow_user_lname', true );
        $arr                  = $array = explode(' ', $user_lastname);    

        // static array which is working
        //$arr = array("Welcome","to", "GeeksforGeeks", "A", "Computer","Science","Portal"); 

        $i=2;

        foreach($arr as $s){
           $i++;
           $sheet->setCellValue('A'.$i, $s);    
        }
endwhile;

1 Answers1

0

This should give you an idea, if your two-dimensional array looks like this.

$parentArray = array(array("first_name"=>"Meck"), array("last_name"=>"Bisk"));

$arraySingle = call_user_func_array('array_merge', $parentArray);

foreach ($arraySingle as $s) {
    $i++;
    $sheet->setCellValue('A'.$i, $s);
}

As done here: php foreach with multidimensional array

Adeolu
  • 11
  • 2