当前位置:网站首页>php中判断版本号是否连续
php中判断版本号是否连续
2022-07-02 06:23:00 【夜空の雪風】
前言
在做excel数据导入到数据库表的过程中需要验证excel中的版本号一栏中的版本号是否连续。
版本号格式:1,1.1,1.2,1.2.1,2,2.1,2.2,2.2.1(正确)
版本号格式:1,1.1,1.1,1.2.1,2,2.1,2.2,2.2.1(错误)
版本号格式:1,1.2,1.1,1.2.1,2,2.2,2.1,2.1.1(错误)
这里需要用到php中的字符串函数,strpos,strrpos,substr。
/** * 判断编号是否连续,编号格式:1,1.1,1.2,1.2.1,2,2.1,2.2,2.2.1 * @param $data * @param string $mark * @return void */
function judge_code_continuity($data, $errData = [], $mark = '.')
{
foreach ($data as $key => $val) {
if (!empty($val)) {
//判断是否存在重复编号
if (in_array($val, array_slice($data, 0, $key))) {
$errData[] = "编号" . $key . "存在重复,请检查以后重新上传";
break;
}
if ($key == 0) {
} else if (!strpos($val, $mark)) {
if (!in_array($val - 1, array_slice($data, 0, $key))) {
$errData[] = $val . "编号存在顺序错误,请检查以后重新上传";
break;
}
} else {
$position = strrpos($val, $mark, 0);
$temp = substr($val, $position + 1, strlen($val) - $position) - 1;
$profit = substr($val, 0, $position);
$pointPosition = strrpos($profit, $mark, 0);
$pointBefore = substr($profit, 0, $pointPosition);
$pointAfter = substr($profit, -1, $pointPosition);
if ($temp == 0) {
if (!in_array(substr($val, 0, $position), array_slice($data, 0, $key))) {
$errData[] = $val . "编号存在顺序错误,请检查以后重新上传";
break;
}
} else {
if (!in_array(substr($val, 0, $position) . "." . ($temp), array_slice($data, 0, $key))) {
$errData[] = $val . "编号存在顺序错误,请检查以后重新上传";
break;
}
}
if ($pointBefore && in_array($pointBefore . "." . ($pointAfter + 1), array_slice($data, 0, $key))) {
$errData[] = $val . "编号存在顺序错误,请检查以后重新上传";
}
}
} else {
continue;
}
}
return $errData;
}
这里会把一串版本号中不正确的返回错误信息。
边栏推荐
- Linux MySQL 5.6.51 Community Generic 安装教程
- Basic knowledge of software testing
- Redis -- cache breakdown, penetration, avalanche
- JS judge whether the object is empty
- Recursion (maze problem, Queen 8 problem)
- AWD learning
- SQLI-LABS通关(less6-less14)
- CTF web practice competition
- JS delete the last character of the string
- Kali latest update Guide
猜你喜欢
In depth study of JVM bottom layer (V): class loading mechanism
table 组件指定列合并行方法
VSCODE 安装LATEX环境,参数配置,常见问题解决
[literature reading and thought notes 13] unprocessing images for learned raw denoising
The win10 network icon disappears, and the network icon turns gray. Open the network and set the flash back to solve the problem
Blog directory of zzq -- updated on 20210601
Win10:添加或者删除开机启动项,在开机启动项中添加在用户自定义的启动文件
Solution to the black screen of win computer screenshot
蚂蚁集团g6初探
Apt command reports certificate error certificate verification failed: the certificate is not trusted
随机推荐
Unexpected inconsistency caused by abnormal power failure; Run fsck manually problem resolved
Uploading attachments using Win32 in Web Automation
Sqli-labs customs clearance (less15-less17)
解决微信小程序swiper组件bindchange事件抖动问题
Uniapp introduces local fonts
Deployment API_ automation_ Problems encountered during test
Recursion (maze problem, Queen 8 problem)
Apt command reports certificate error certificate verification failed: the certificate is not trusted
Date time API details
How to debug wechat built-in browser applications (enterprise number, official account, subscription number)
CTF web practice competition
Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
SQLI-LABS通关(less15-less17)
Latex error: the font size command \normalsize is not defined problem solved
Fe - wechat applet - Bluetooth ble development research and use
There are multiple good constructors and room will problem
20201002 vs 2019 qt5.14 developed program packaging
Fe - eggjs combined with typeorm cannot connect to the database
There is no way to drag the win10 desktop icon (you can select it, open it, delete it, create it, etc., but you can't drag it)