---
title: "PHP. 在判断语句中，0值的$_POST想到于false"
author: "DBear"
date: "2011-11-25T19:03:26Z"
tags: []
categories: ["编程语言"]
slug: "php-0-post-false"
draft: false
lastmod: "2011-11-25T19:03:26Z"
id: 1278589
url: "https://dbear.iteye.com/blog/1278589"
---

好吧，今天又因为由基础不扎实而导致的低级错误耽误了好多时间。。。。

 

我从前端取到一个价格数据传回后台，使用$\_POST\['price']接收。原本代码中设置了对price参数是否存在的判断，我是这么写的。。。。

 

```
if($_POST['price']) {
    //do something
}
```

 

结果发现，对于 price = "0" 这种传入值始终无法执行“something”。 原因就是在php的if判断中 if(“0”) 相当于 if(false)。

于是我改成:

 

```
if($_POST['price'] != null) {
    //do something
}
```

 

世界从此宁静了~~~~