当前位置:网站首页>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操作。
边栏推荐
- Duchefa low melting point agarose PPC Chinese and English instructions
- Material design component - use bottomsheet to show extended content (II)
- go 文件路径操作
- PHP反序列化+MD5碰撞
- Duchefa MS medium contains vitamin instructions
- Material Design组件 - 使用BottomSheet展现扩展内容(二)
- Monorepo管理方法论和依赖安全
- 解析五育融合之下的steam教育模式
- Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral
- haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
猜你喜欢

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

中国的软件公司为什么做不出产品?00后抛弃互联网;B站开源的高性能API网关组件|码农周刊VIP会员专属邮件周报 Vol.097

Abnova丨 MaxPab 小鼠源多克隆抗体解决方案

Duchefa low melting point agarose PPC Chinese and English instructions

ClickHouse 复制粘贴多行sql语句报错

2022 Beijing eye health products exhibition, eye care products exhibition, China eye Expo held in November

Duchefa细胞分裂素丨二氢玉米素 (DHZ)说明书

PHP反序列化+MD5碰撞

Prosci LAG-3 recombinant protein specification

CADD course learning (7) -- Simulation of target and small molecule interaction (semi flexible docking autodock)
随机推荐
[record of question brushing] 1 Sum of two numbers
Binary search
科普|英语不好对NPDP考试有影响吗 ?
Abnova CRISPR spcas9 polyclonal antibody protocol
Cutting edge technology for cultivating robot education creativity
最长摆动序列[贪心练习]
Abnova丨DNA 标记高质量控制测试方案
ProSci LAG-3 重组蛋白说明书
挖财商学院给的证券账户安全吗?可以开户吗?
Duchefa MS medium contains vitamin instructions
Abnova fluorescent dye 620-m streptavidin scheme
从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
Matplotlib drawing retouching (how to form high-quality drawings, such as how to set fonts, etc.)
解读协作型机器人的日常应用功能
线程池的使用
14、Transformer--VIT TNT BETR
hdu2377Bus Pass(构建更复杂的图+spfa)
Abnova丨荧光染料 620-M 链霉亲和素方案
教你自己训练的pytorch模型转caffe(一)
National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition