PHP data type N...LOGIN

PHP data type NULL type

Empty means null in English, which means nothing. Null is not false, not 0, and not a space.

[Key points] Know the three situations when null occurs, and learn the difference between empty and isset functions.

There are three main situations that will produce a null type:

1. The value of the variable is clearly specified as NULL through variable assignment

2. A variable has no Give any value

3. Use the function unset() to destroy the variable

Let’s demonstrate it with code.

<?php
//声明变量为null
$n = null;
var_dump($n);
?>
<?php
//var_dump显示输出变量$meiyou,看看结果是什么?
var_dump($meiyou);
?>
<?php
//声明一个变量$iphone的值为字符串的手机
$iphone = '手机';
//unset销毁掉一个变量unset($iphone);
var_dump($iphone);
?>

Next we will explain two functions related to null. These two functions are very commonly used. We define the level as [default level].

empty() can pass a variable into the middle of the brackets. If the value of this variable is false or null, it returns true.

<?php

$apple = null;
if(empty($apple)){
    echo '执行了真区间,凤姐,我爱你';
}else{
   echo '行了假区间,你想凤姐了';
}
?>

The above experiment proves that $apple is null. Place the apple in the middle of empty. The result is a true interval.

isset() can pass one or more variables between the brackets, separated by commas. As long as there is a variable that is null, it returns false. Otherwise, returns true.

<?php
//待会儿将变量$jia改为null再执行看看结果
$jia = false;

$result = isset($jia);

var_dump($result);

?>
<?php
$one = 10;
$two = false;
$three = 0;
$four = null;

$result = isset($one , $two , $three , $four);
//执行看看结果,是不是
var_dump($result);

?>

unset() The function of this function is to destroy variables. Insert the variable name you want to destroy between the unset (variable) brackets, and the variable will be destroyed.

English description
unset
Pronunciation: [ʌn'set]
Explanation: Restoration

Next Section
<?php $one = 10; $two = false; $three = 0; $four = null; $result = isset($one , $two , $three , $four); //执行看看结果,是不是 var_dump($result); ?>
submitReset Code
ChapterCourseware