当前位置:网站首页>php中explode函数存在的陷阱
php中explode函数存在的陷阱
2022-07-05 20:50:00 【风神幻龙】
一般情况下,都是在参数非空的情况下进行explode操作,例如
$a = "a,b,c";
$b = explode(',',$a);
此时会返回结果
array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" }
但是如果传入的参数为空呢?
$a = '';
$b = explode(',',$a);
此时会返回什么样的结果呢,是不是会认为返回
array(0) { }
其实不是,它会返回
array(1) { [0]=> string(0) "" }
如果你把它当做空数组处理,那么后续的逻辑统统会出错,因为它并不是一个空数组,empty并不能使它返回true,因此在使用explode的时候一定要注意第二个参数的值,最好先进行非空判断,之后再进行explode操作。
边栏推荐
猜你喜欢

解读协作型机器人的日常应用功能

线程池的使用

Open source SPL eliminates tens of thousands of database intermediate tables

ProSci LAG-3 重组蛋白说明书

基于flask写一个接口

IC popular science article: those things about Eco

Welcome to the game and win rich bonuses: Code Golf Challenge officially launched

Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Nanjing

王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动

研學旅遊實踐教育的開展助力文旅產業發展
随机推荐
10000+ 代码库、3000+ 研发人员大型保险集团的研发效能提升实践
Abbkine BCA法 蛋白质定量试剂盒说明书
CVPR 2022 | common 3D damage and data enhancement
Usaco3.4 "broken Gong rock" band raucous rockers - DP
启牛2980有没有用?开户安全吗、
CareerCup它1.8 串移包括问题
14、Transformer--VIT TNT BETR
ClickHouse 复制粘贴多行sql语句报错
ProSci LAG3抗体的化学性质和应用说明
国外LEAD美国简称对照表
表单文本框的使用(二) 输入过滤(合成事件)
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
MySQL fully parses json/ arrays
Is the securities account given by the school of Finance and business safe? Can I open an account?
实现浏览页面时校验用户是否已经完成登录的功能
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
Implementation of redis unique ID generator
Composition of applet code
《SAS编程和数据挖掘商业案例》学习笔记# 19
Prosci LAG-3 recombinant protein specification