循环添加到数组中php,如何在for循环中将另一行添加到PHP中的数组中

嘿家伙,我有以下几点:

for($i; $i< count($nontimedif); $i++){

$data[$i] = array(

"Driver Chose Non-Compliance:" => $nontimedif[$i] . ",

" . $nonfirstname[$i]. ",

" . $nonlastname[$i]. ",

" . $nonemail[$i]. ",

" . .......

);

}所以在运行之后,我想添加一些新行,因为这不是传输到.csv文件。那么我怎么在最后添加呢?

我如何制作.csv文件:

function cleanData(&$str)

{

// escape tab characters

$str = preg_replace("/\t/", "\\t", $str);

// escape new lines

$str = preg_replace("/\r?\n/", "\\n", $str);

// convert 't' and 'f' to boolean values

if($str == 't') $str = 'TRUE';

if($str == 'f') $str = 'FALSE';

// force certain number/date formats to be imported as strings

if(preg_match("/^0/", $str) || preg_match("/^\+?\d{8,}$/", $str) || preg_match("/^\d{4}.\d{1,2}.\d{1,2}/", $str)) {

$str = "'$str";

}

// escape fields that include double quotes

if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';

}

// filename for download

$filename = "website_data_" . date('Ymd') . ".xls";

header("Content-Disposition: attachment; filename=\"$filename\"");

header("Content-Type: application/vnd.ms-excel");

$flag = false;

foreach($data as $row) {

if(!$flag) {

// display field/column names as first row

echo implode("\t", array_keys($row)) . "\r\n";

$flag = true;

}

array_walk($row, 'cleanData');

echo implode("\t", array_values($row)) . "\r\n";

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值