我在CSV文件中导出数据有问题。当我传递"静态数据"时然后出口。但是我想要的是动态的即user_name或user_lastname存储我的数据。所以,任何人都可以帮我摆脱困境。
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;
如果你的二维数组是这样的,这应该会给你一个概念。
$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);
}
php foreach with多维数组