目錄
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

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++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教學
1655
14
CakePHP 教程
1413
52
Laravel 教程
1306
25
PHP教程
1252
29
C# 教程
1226
24
適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南 適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南 Dec 24, 2024 pm 04:42 PM

PHP 8.4 帶來了多項新功能、安全性改進和效能改進,同時棄用和刪除了大量功能。 本指南介紹如何在 Ubuntu、Debian 或其衍生版本上安裝 PHP 8.4 或升級到 PHP 8.4

在PHP API中說明JSON Web令牌(JWT)及其用例。 在PHP API中說明JSON Web令牌(JWT)及其用例。 Apr 05, 2025 am 12:04 AM

JWT是一種基於JSON的開放標準,用於在各方之間安全地傳輸信息,主要用於身份驗證和信息交換。 1.JWT由Header、Payload和Signature三部分組成。 2.JWT的工作原理包括生成JWT、驗證JWT和解析Payload三個步驟。 3.在PHP中使用JWT進行身份驗證時,可以生成和驗證JWT,並在高級用法中包含用戶角色和權限信息。 4.常見錯誤包括簽名驗證失敗、令牌過期和Payload過大,調試技巧包括使用調試工具和日誌記錄。 5.性能優化和最佳實踐包括使用合適的簽名算法、合理設置有效期、

您如何在PHP中解析和處理HTML/XML? 您如何在PHP中解析和處理HTML/XML? Feb 07, 2025 am 11:57 AM

本教程演示瞭如何使用PHP有效地處理XML文檔。 XML(可擴展的標記語言)是一種用於人類可讀性和機器解析的多功能文本標記語言。它通常用於數據存儲

解釋PHP中的晚期靜態綁定(靜態::)。 解釋PHP中的晚期靜態綁定(靜態::)。 Apr 03, 2025 am 12:04 AM

靜態綁定(static::)在PHP中實現晚期靜態綁定(LSB),允許在靜態上下文中引用調用類而非定義類。 1)解析過程在運行時進行,2)在繼承關係中向上查找調用類,3)可能帶來性能開銷。

php程序在字符串中計數元音 php程序在字符串中計數元音 Feb 07, 2025 pm 12:12 PM

字符串是由字符組成的序列,包括字母、數字和符號。本教程將學習如何使用不同的方法在PHP中計算給定字符串中元音的數量。英語中的元音是a、e、i、o、u,它們可以是大寫或小寫。 什麼是元音? 元音是代表特定語音的字母字符。英語中共有五個元音,包括大寫和小寫: a, e, i, o, u 示例 1 輸入:字符串 = "Tutorialspoint" 輸出:6 解釋 字符串 "Tutorialspoint" 中的元音是 u、o、i、a、o、i。總共有 6 個元

PHP和Python:比較兩種流行的編程語言 PHP和Python:比較兩種流行的編程語言 Apr 14, 2025 am 12:13 AM

PHP和Python各有優勢,選擇依據項目需求。 1.PHP適合web開發,尤其快速開發和維護網站。 2.Python適用於數據科學、機器學習和人工智能,語法簡潔,適合初學者。

什麼是PHP魔術方法(__ -construct,__destruct,__call,__get,__ set等)並提供用例? 什麼是PHP魔術方法(__ -construct,__destruct,__call,__get,__ set等)並提供用例? Apr 03, 2025 am 12:03 AM

PHP的魔法方法有哪些? PHP的魔法方法包括:1.\_\_construct,用於初始化對象;2.\_\_destruct,用於清理資源;3.\_\_call,處理不存在的方法調用;4.\_\_get,實現動態屬性訪問;5.\_\_set,實現動態屬性設置。這些方法在特定情況下自動調用,提升代碼的靈活性和效率。

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

See all articles