The PHP is_null() function is actually an in-built function of the PHP Programming Language which help us to find whether the variable is a NULL value or not. The PHP is_null() function works for PHP 4 and the above PHP versions which are introduced later after PHP 4 version. The type of the $variable_name parameter of the is_null() function is Boolean type value. Is_null() function of PHP accepts only one parameter and that too it is fully mandatory parameter. There are no optional parameters available inside of the is_null() PHP function.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax:
is_null( $variable_name )
Explanation of Parameter:
The is_null() function of PHP Programming Language usually accepts only one single parameter as mentioned in the above syntax.
$variable_name:The $variable name helps us to check whether the variable’s value is NULL or not. It is a mandatory parameter. There are no more optional parameters available inside of the is_null() function to mention.
Return value:
The is_null() function will return a Boolean value and the function is going to return TRUE only when the $variable_name is the NULL value, if the variable’s value is not NULL then it will return FALSE statement.
Working of is_null() Function in PHP
- PHP is_null() function woks based on the NULL values present inside of the function’s parenthesis.
- If the variable value inside of the is_null() function then the result will be TRUE and promotes the further conditions statement or any other.
- If the variable’s value inside of the is_null() function is FALSE then statements which are inside of the those conditions will not be executed.
- The value type of the PHP is_null() function is Boolean.
- The only parameter of the is_null() function is a mixed type (mixed type means that it is going to indicate that the parameter has the capability of accepting the multiple types but not necessarily all types).
Examples of PHP is_null()
Given below are the examples mentioned:
Example #1
In the below example, four variables is created with different variables and checked whether they are NULL values or not with the help of is_null() function of the PHP programming language. At first, $var11, $var12, $var13 and $var14 variables are created with different values for them. $var11 and $var13 variables are stored with “NULL” values. $var12 and $var14 values are stored with “\0” and 0 values. \0 is considered as NULL but here it is assigned as a string value. Then “is_null() ? TRUE : FALSE” structured syntax is used to print the TRUE statements/others only if the is_null($variable_name) is TRUE. If not FALSE statement will be printed. Likewise the code implements the results below. Checking the $var11 and $var13 variable’s values using the is_null() function will print the TRUE value whereas for other variables ($var12 and $var14) the result will be FALSE value.
Code:
<?php $var11 = NULL; $var12 = "\0"; $var13 = "NULL"; $var14 = 0; is_null($var11) ?print_r("Null Value So True\n") : print_r("False\n"); is_null($var12) ?print_r("Null Value So True\n") : print_r("Not Null so False\n"); is_null($var13) ?print_r("Null Value So True\n") : print_r("Not Null so False\n"); is_null($var14) ?print_r("Null Value So True\n") : print_r("Not Null so False\n"); ?>
Output:
Example #2
This is the example of demonstrating the working of the is_null() function of the PHP Programming Language. At first, a function “check_null1()” is created with only one parameter “$var11” in it. Inside of the function is_null() function is created to check whether the variable parameter of the function is TRUE or NOT. But here variable value of $var11 is not mentioned. Function is closed and called many times with different inputs. “NULL” is mentioned/passed to the $var11 by changing the capitalization of the NULL words as values. But for the last 3 echo statements, different values passed to the variable parameter of the function. So for the last echo statements the result will be FALSE.
Code:
<?php function check_null1($var11) { return (is_null($var11) ? "Null Value so :: True" : "Not Null Value so :: False"); } echo check_null1(NULL) . "\n"; echo check_null1(null) . "\n"; echo check_null1(Null) . "\n"; echo check_null1(NUll) . "\n"; echo check_null1(NULl) . "\n"; echo check_null1(nulL) . "\n"; echo check_null1(nuLL) . "\n"; echo check_null1(nULL) . "\n"; echo check_null1('Nul') . "\n"; echo check_null1(false) . "\n"; echo check_null1(2). "\n"; ?>
Output:
Example #3
In the below example, $a1, $b1, $c1 and $d1 variables are created. NULL values are passed to $b1 and $d1 variables. Although “null” value is passed to the $c1 variable, but the NULL is passed as a string value. So the result of the $b1 and $d1 variable’s after checking with the is_null() function will be printed as empty value. For $a1 and $c1 variables, result will not all be print.
Code:
<?php echo "For Non-NULL values the value will not be printed . Check Below :: \n"; $a1 = 0; echo "a1 is :: " . is_null($a1) . "\n"; $b1 = null; echo "b1 is :: " . is_null($b1) . "\n"; $c1 = "null"; echo "c1 is :: " . is_null($c1) . "\n"; $d1 = NULL; echo "d1 is :: " . is_null($d1) . "\n"; ?>
Output:
Example #4
This is the example of checking for different $var11 variable’s values whether they are NULL or not. This is done by using different IF and ELSE conditions. At first, $var11 is stored with “TRUE” value and checked with the is_null() function so the ELSE condition result will be printed because the is_null(TRUE) function condition result is FALSE. Likewise for the second IF and ELSE condition, same result is printed. Then for the $var11 variable, “NULL” value is passed and then after checking with the is_null() function the result will show that “Variable var11 is NULL” like that.
Code:
<?php echo "Checking for TRUE value of the var11 variable for NULL :: \n"; $var11 = TRUE; if (is_null($var11)) { echo 'Variable var11 is NULL'; } else { echo 'Variable var11 is not NULL'; } echo "\n"; echo "Checking for FALSE value of the var11 variable for NULL :: \n"; $var11 = FALSE; if (is_null($var11)) { echo 'Variable var11 is NULL'; } else { echo 'Variable var11 is not NULL'; } echo "\n"; echo "Checking for NULL value of the var11 variable for NULL :: \n"; $var11 = NULL; if (is_null($var11)) { echo 'Variable var11 is NULL'; } else { echo 'Variable var11 is not NULL'; } echo "\n"; ?>
Output:
Conclusion
Here we saw introduction of PHP is_null() function with the syntax and it’s parameters explanation, working of PHP is_null() function along with various examples which involves is_null() function to understand the is_null() function well.
以上是PHP is_null()的详细内容。更多信息请关注PHP中文网其他相关文章!

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

Dreamweaver CS6
视觉化网页开发工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),