Home > php教程 > php手册 > php中的字符串如何对负值进行判断

php中的字符串如何对负值进行判断

WBOY
Release: 2018-10-25 16:50:46
Original
2176 people have browsed it

这篇文章主要介绍了php字符串操作针对负值的判断,实例分析了php字符串操作中针对负值的判断技巧,需要的朋友可以参考下

$a = '-1';
$b = (int)$a;
$c = is_numeric($a);
if ($a) {
 echo 1; //echo 1
} else {
 echo 2;
}
var_dump($b); // int(-1)
var_dump($c); // true
Copy after login

运行结果输出如下:

1
int -1
boolean true

总结:

字符串 '-1'的逻辑值是true;

【相关教程推荐】

1. php编程从入门到精通全套视频教程 

2. php从入门到精通  

3. bootstrap教程 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template