// 加载文件
$spreadsheet = IOFactory::load($attachment);
// 读取内容
$sheetData = $spreadsheet->getSheet(0)->toArray(null, true, true, true);
// 循环检查数据
$allData = [];
$allError = [];
foreach ($sheetData as $key => $val) {
if ($key == 1) {
continue;
}
// 跳过空行
$val = array_map('trim', $val); // 去除首尾空格
if (empty(array_filter($val))) {
continue;
}
try {
$allData[] = $this->checkAndConvertItem($val);
} catch (\Exception $exception) {
$error = '第A' . $key . '行,此题需要检查,' . $exception->getMessage();
$allError[] = $error;
}
}通过array_filter过滤即可
<!doctype html> <html> <head> <meta charset="utf-8"> <title>demo</title> </head> <bod...
【一】.抽象类假设如下场景:团队准备开发某网站,表建好了,页面设计好了.A组负责开发底层数据库操作类(DB),B组负责调用DB类.但是此时A组发生了争执,MySQL? Oracle? DB2? sqlite?到底使用什么数据库?B组.... 进入漫长的等待.解决方法:A组和B组 先定1个数据库类的模...
应用场景:PHP模拟购买,商品数量大于0才能购买常见代码:<?php //连接数据库 $con=mysqli_connect("localhost","ihuohuo","927464cy","ihuohuo");...
源码:特别适用于微信支付中通知微信支付网关function array2xml($arr, $level = 1) { $s = $level == 1 ? "<xml&g...
如果想在windows中执行php,并且让php脚本在后台运行,可以用下面的cmd命令start /b php D:\wwwroot\default\demo1\run.php例如上面的命令意思后台运行run.php,如果想用php编写异步代码: ...
在编写多进程的实例中我在每个进程中使用如下代码://调用等待信号的处理器 while (true) { pcntl_signal_dispatch(); }开启5个进程,cpu直接100%修正之后的代码://调用等待信号的处理器 while&...