布尔转换为整数值PHP [英] Convert boolean to integer value php

查看:748
本文介绍了布尔转换为整数值PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有PHP,将采取一个布尔值,并返回其整数相当于任何内建的功能? 0 FALSE,1为TRUE?
当然,你可以很容易地创建一个函数来做到这一点,我只是问,如果有PHP内部的内置函数。我已经尝试过 INTVAL(),并将其转换为(INT),但他们没有工作,他们在这两种情况下返回0真假。

Is there any builtin function for PHP that will take a boolean value and return its integer equivalent? 0 for FALSE, 1 for TRUE? Of course you can easily create a function to do so, I'm just asking if there is a builtin function inside of PHP. I already tried intval() and casting it to (int) but they didnt work, they return 0 in both cases of TRUE and FALSE.

编辑:问题是,它真的wasnt一个布尔值,它是一个字符串false,真,PHP剪掉检测到它通过一个布尔jQuery的岗位。解决的问题,谢谢!

Edit : the problem was that it wasnt really a boolean, it was a string "false", "true", php didnt detect the jquery post that it passed a boolean. problem solved, thanks !

推荐答案

<一个href=\"http://www.php.net/manual/fr/language.types.integer.php\">http://www.php.net/manual/fr/language.types.integer.php

通常情况下,简单地 $敏=(INT)$ myBoolean 应该工作,你能告诉我们,否则你的code?

Normally, simply $myInt = (int)$myBoolean should work, can you show us your code otherwise ?

这篇关于布尔转换为整数值PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆