目录
Working of is_null() Function in PHP
Examples of PHP is_null()
Example #4
Conclusion
首页 后端开发 php教程 PHP is_null()

PHP is_null()

Aug 29, 2024 pm 12:53 PM
php

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:

PHP is_null()

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:

PHP is_null()

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:

PHP is_null()

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:

PHP is_null()

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中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

<🎜>:泡泡胶模拟器无穷大 - 如何获取和使用皇家钥匙
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系统,解释
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆树的耳语 - 如何解锁抓钩
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

Java教程
1674
14
CakePHP 教程
1429
52
Laravel 教程
1333
25
PHP教程
1278
29
C# 教程
1257
24
PHP与Python:了解差异 PHP与Python:了解差异 Apr 11, 2025 am 12:15 AM

PHP和Python各有优势,选择应基于项目需求。1.PHP适合web开发,语法简单,执行效率高。2.Python适用于数据科学和机器学习,语法简洁,库丰富。

PHP:网络开发的关键语言 PHP:网络开发的关键语言 Apr 13, 2025 am 12:08 AM

PHP是一种广泛应用于服务器端的脚本语言,特别适合web开发。1.PHP可以嵌入HTML,处理HTTP请求和响应,支持多种数据库。2.PHP用于生成动态网页内容,处理表单数据,访问数据库等,具有强大的社区支持和开源资源。3.PHP是解释型语言,执行过程包括词法分析、语法分析、编译和执行。4.PHP可以与MySQL结合用于用户注册系统等高级应用。5.调试PHP时,可使用error_reporting()和var_dump()等函数。6.优化PHP代码可通过缓存机制、优化数据库查询和使用内置函数。7

PHP和Python:比较两种流行的编程语言 PHP和Python:比较两种流行的编程语言 Apr 14, 2025 am 12:13 AM

PHP和Python各有优势,选择依据项目需求。1.PHP适合web开发,尤其快速开发和维护网站。2.Python适用于数据科学、机器学习和人工智能,语法简洁,适合初学者。

PHP行动:现实世界中的示例和应用程序 PHP行动:现实世界中的示例和应用程序 Apr 14, 2025 am 12:19 AM

PHP在电子商务、内容管理系统和API开发中广泛应用。1)电子商务:用于购物车功能和支付处理。2)内容管理系统:用于动态内容生成和用户管理。3)API开发:用于RESTfulAPI开发和API安全性。通过性能优化和最佳实践,PHP应用的效率和可维护性得以提升。

PHP的持久相关性:它还活着吗? PHP的持久相关性:它还活着吗? Apr 14, 2025 am 12:12 AM

PHP仍然具有活力,其在现代编程领域中依然占据重要地位。1)PHP的简单易学和强大社区支持使其在Web开发中广泛应用;2)其灵活性和稳定性使其在处理Web表单、数据库操作和文件处理等方面表现出色;3)PHP不断进化和优化,适用于初学者和经验丰富的开发者。

PHP和Python:解释了不同的范例 PHP和Python:解释了不同的范例 Apr 18, 2025 am 12:26 AM

PHP主要是过程式编程,但也支持面向对象编程(OOP);Python支持多种范式,包括OOP、函数式和过程式编程。PHP适合web开发,Python适用于多种应用,如数据分析和机器学习。

PHP与其他语言:比较 PHP与其他语言:比较 Apr 13, 2025 am 12:19 AM

PHP适合web开发,特别是在快速开发和处理动态内容方面表现出色,但不擅长数据科学和企业级应用。与Python相比,PHP在web开发中更具优势,但在数据科学领域不如Python;与Java相比,PHP在企业级应用中表现较差,但在web开发中更灵活;与JavaScript相比,PHP在后端开发中更简洁,但在前端开发中不如JavaScript。

PHP和Python:代码示例和比较 PHP和Python:代码示例和比较 Apr 15, 2025 am 12:07 AM

PHP和Python各有优劣,选择取决于项目需求和个人偏好。1.PHP适合快速开发和维护大型Web应用。2.Python在数据科学和机器学习领域占据主导地位。

See all articles