当前位置:网站首页>「PHP基础知识」布尔型的使用
「PHP基础知识」布尔型的使用
2022-07-27 05:04:00 【夜晚回家】
功能要求
下面在if条件语句中判断变量$b中的值是否为true,如果为true,则输出“变量$b为真!”,否则输出“变量$b为假!”
实例代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>布尔变量示例</title>
</head>
<body>
<?php
$b = true;
if($b == true){
echo '变量$b为真!';
}else{
echo '变量$b为假!';
}
?>
</body>运行结果
知识说明
PHP的数据类型可以分为3种,即标量数据类型【boolean(布尔型)、integer(整型)、float/double(浮点型)和string(字符串型)】、复合数据类型和【array(数组)和object(对象)】特殊数据类型。【resource(资源)与null(空值)。】
标量数据类型是数据结构中最基本的单元,只能存储一个数据。PHP中标量数据类型又细分为4种。
布尔型是PHP中较为常用的数据类型之一,它保存一个true值或者false值,其中true和false是PHP的内部关键字。设定一个布尔值的变量,只需将true或者false赋值给变量即可。
注意:在PHP中不只有false值才为假的,在一些特殊情况下如0、0.0、"0"、空白字符串("")、只声明没有赋值的数组等也被认为是false。
说明:美元符号$是变量的标识符,所有变量都是以$符号开头的,无论是声明变量还是调用变量,都应使用$符号。
边栏推荐
猜你喜欢

Hi3516dv300 environment setup

Program environment and preprocessing (Part 2): define, undef, command line compilation, conditional compilation, file inclusion (super full collation, recommended collection!!!

JS中原型及原型链

Source code of document type full-text retrieval knowledge base management system

node 安装调试

First acquaintance with C language - first acquaintance with pointer

用户页面管理

退出登录与jsx显示

Gallerycms download, installation and configuration
![[极客大挑战 2019]FinalSQL 1](/img/a7/857d47639fcb38e0055a2444206b8c.png)
[极客大挑战 2019]FinalSQL 1
随机推荐
权限展示-左侧列表动态化
路由的配置和前往登录首页进行发送请求
Logic of image uploading
Configure the route and go to the login home page to send the request
C语言入门介绍
一本通1201——斐波那契数列
元素显示模式:块级,行内,行内块,嵌套规范,显示模式转换
[MRCTF2020]Ezpop 1
Source code of document type full-text retrieval knowledge base management system
我的第一篇博客
MySQL cancels the foreign key Association constraint
[极客大挑战 2019]FinalSQL 1
Initial C language -- the function of keyword static
JS中什么是DOM和BOM
Xiaomi mall project_ register
Permission configuration, component value transfer
Share a multiple-choice question about variables (including global variables, local variables, the scope of variables, and life cycle knowledge points)
C语言字符串介绍以及相关操作函数
背景图片相关应用-铺满,自适应
set集合