当前位置:网站首页>「PHP基础知识」空值(null)的使用
「PHP基础知识」空值(null)的使用
2022-08-02 03:16:00 【夜晚回家】
功能要求
定义字符串变量$string1直接赋值为null;使用没有被声明和赋值的变量$string2;定义字符串$string3被赋予初始值为“str”,但对字符串变量$string3使用unset()函数处理,分别将打印前$string3的值和使用后$string3的值输出。
实例代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>被赋值为null的几种情况</title>
</head>
<body>
<?php
echo "变量(\$string1)直接赋值为null:";
$string1 = null;
$string3 = "str";
if(is_null($string1)){
echo "string1 = null";
}
echo "<p>变量(\$string2)未被赋值:";
if(is_null($string2)){
echo "string2 = null";
}
echo "<p>被unset()函数处理过的变量(\$string3):";
unset($string3);
if(is_null($string3)){
echo "string3 = null";
}
?>
</body>运行结果
知识说明
空值表示没有为该变量设置任何值。另外,空值(null)不区分大小写,null和NULL效果是一样的。被赋值空值的情况有以下三种:还没有赋任何值、被赋值null、被unset()函数处理过的变量。unset()函数的作用就是从内存中删除变量。
说明:is_null()函数是判断变量是否为null,该函数返回一个boolean型,如果变量为null,则返回true,否则返回false。unset()函数用来销毁指定的变量。
注意:从PHP4.0开始,unset()函数就不再有返回值,不要试图获取或输出unset()。
边栏推荐
- Difference between #{} and ${}
- Keil开发环境安装教程
- 总体写作原则
- Daily practice------There are n integers, so that the previous numbers are moved back m positions in order, and the last m numbers become the first m numbers
- PHP WebSehll backdoor script and detection tool
- MySQL8 -- use msi (graphical user interface) under Windows installation method
- Heao Technology Network Interview (with reference answers)
- (转帖)HashCode总结(2)
- WebShell Feature Value Summary and Detection Tool
- 线性代数学习笔记3-2:矩阵乘法的理解
猜你喜欢
随机推荐
LeetCode:1161. 最大层内元素和【BFS层序遍历】
DOM破坏及复现实验
MongoDB文档存储
(转帖)hashcode和equals的关系
分布式事务解决方案模型
第十一天&shell脚本
7-41 PAT排名汇总 (25 分)多样排序
AntV X6制作画板工具(图形,线段,图片上传)
JSP WebSehll backdoor script
三维数字孪生引擎与实景互动,案例解析
Good Key, Bad Key (thinking, temporary exchange, classic method)
ASP WebShell backdoor script and anti-kill
centos安装mysql8
bgp机房的动态路由和静态路由的区别
小程序(开发必备常识)1
基于可逆网络的单一图像超分辨率
代码随想录笔记_哈希_383赎金信
MySQL8 -- use msi (graphical user interface) under Windows installation method
Webshell upload method
Redis安装,基本命令,持久化方式,集群









