简体   繁体   English

"如何使用php在while循环中添加数组"

[英]how to add array inside while loop with php

My end goal is to create a csv file from an array built inside the while loop.我的最终目标是从 while 循环内构建的数组创建一个 csv 文件。 I'm building this array exactly as the columns the user sees on the html page.我正在构建这个数组,就像用户在 html 页面上看到的列一样。 From 5 onwords its just stats from db.从 5 开始,它只是来自 db 的统计数据。

$csvline = Array ( [0] => 4 [1] => 2-Apr-2018 [2] => Name [3] => Company [4] => Branch [5] => 6761 [6] => 1192 [7] => 33 [8] => 0 [9] => 5 [10] => 0 [11] => 0 [12] => 0 [13] => 0 [14] => 0 [15] => 0 [16] => 0 [17] => 0 [18] => 0 [19] => 0 [20] => 0 [21] => 0 [22] => 1 [23] => 3 [24] => 0 [25] => 0 [26] => 0 [27] => 0 [28] => 0 [29] => 0 [30] => 0 [31] => 0 [32] => 0 [33] => 0 ) $csvline = 数组 ( [0] => 4 [1] => 2018 年 4 月 2 日 [2] => 名称 [3] => 公司 [4] => 分公司 [5] => 6761 [6] => 1192 [7] => 33 [8] => 0 [9] => 5 [10] => 0 [11] => 0 [12] => 0 [13] => 0 [14] => 0 [ 15] => 0 [16] => 0 [17] => 0 [18] => 0 [19] => 0 [20] => 0 [21] => 0 [22] => 1 [23] => 3 [24] => 0 [25] => 0 [26] => 0 [27] => 0 [28] => 0 [29] => 0 [30] => 0 [31] => 0 [32] => 0 [33] => 0)

My question is, How can I add the array to the next array created inside the while loop Almost like $csvlines.=$csvline but for the array.我的问题是,如何将数组添加到在 while 循环中创建的下一个数组中 几乎像 $csvlines.=$csvline 但对于数组。

"

Try this $arr = []; $arr[] = 1; $arr[] = 5;试试这个$arr = []; $arr[] = 1; $arr[] = 5; $arr = []; $arr[] = 1; $arr[] = 5;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM