PHP: null (NULL) data type instance detailed

Source: Internet
Author: User
What is a null value (NULL)?

A null value, like its name, indicates that a variable has no value. A null value (NULL) is not case-sensitive, that is, NULL is the same as null or NULL.

There are three scenarios in which null values are given in PHP:

The first type:

has not been assigned a value

<?php$a;var_dump ($a);? >

Code Run Result:

The second type:

is assigned a value of NULL.

<?php$nu=null;var_dump ($NU);? >

Code Run Result:

The third type:

Variables processed by the unset () function

<?php$name = ' Felipe '; Var_dump ((unset) $name);? >

Code Run Result:

Instance

The string string1 is assigned a value of null,string2 and is not declared and assigned at all, so the output is null, and the last string3, although given the initial value, is also null after being processed by the unset () function. The function of the unset () function is to remove variables from memory. The code is as follows:

<?phpheader ("Content-type:text/html;charset=utf-8"); Echo  "variable ($string 1) is directly assigned null"; $string =null;                                          $string 1 is assigned the null value $string3= "str";                                      $string 3 is assigned Strif (Is_null ($strig 1=null)) {                    //determines if $string1 is empty    echo ' String=null ';} Echo ' <p> ', echo ' variable ($string 2) not assigned '; if (Is_null ($string 2=null)) {                 //Determine if $string1 is empty    echo ' String=null ' ;} Echo ' <p> ', Echo ' was released by Unset ($string 3): '; unset ($string 3), if (Is_null ($string 3=null)) {//To determine if $string1 is empty    echo ' String=null ';}? >

Code Run Result:

The Is_null function is used to determine if a variable is null, as we'll see later, now that this function returns a Boolean, if the variable is null, returns True, otherwise false. The unset () function is used to destroy known variables.

In the next section, we explain "how to convert PHP data types".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.