php - 为什么 boolval(false) 在 php 中返回空?

标签 php

我有点困惑php函数如何boolval作品。考虑以下因素

<?php echo boolval(true); // prints 1

与对比

<?php echo boolval(false); // prints nothing?

为什么我没有返回真/假?为什么是 boolval(false)什么都不返回?

我在尝试解析 $argv 时遇到了这个问题对于 bool 参数。从 $argv 中提取 bool 值的正确做法是什么?如果没有这个功能?

最佳答案

来自php manual

A boolean TRUE value is converted to the string "1". Boolean FALSE is converted to "" (the empty string). This allows conversion back and forth between boolean and string values.

使用

echo $boolres ? 'true' : 'false';

关于php - 为什么 boolval(false) 在 php 中返回空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38101560/

相关文章:

php - 我收到此错误错误 : Incorrect time value: '16:44:09 PM' for column 'time' at row 1 and I'm not sure why

php - 使用 PHP 下载 Youtube 视频

javascript - Jquery 复选框最大选中数

php - 聊天框注销消息

javascript - 具有重定向功能的 Windows 警报 javascript

php - 使用php将数据插入mysql表时遇到问题

php - 如果 li 标签的开始和结束标签位于 span 开始和结束标签之间,则替换 li 标签

javascript - 根据angularjs中的url更改body类

php - 单个页面上有多个网格

PHP 创建类似 phpmyadmin 的复制命令