PHP variable definition and use

Source: Internet
Author: User

1 No pre-defined use required

2 in PHP the type is declared variable must be used with a dollar sign $ followed by a variable to represent such as $a=100; $b = "string"

The unset () function releases the specified variable

The Isset () function detects if a variable is set

The empty () function detects if a variable is empty

Example:

<?php

$var = ""; Declare variable $var to give a null value

if (empty ($var))

{echo ' $var is either 0 or not set at all ';}

if (Isset ($var))

{echo ' $var is not set at all ';} The result is true. Because $var has been set

Unset ($var);

if (Isset ($var))

{print "This var was set so I'll print.";}

?>

Variable naming

1 variable names are strictly case-sensitive, but built-in structures and keywords and user-defined class names and function names are case-insensitive.

For example, echo while class, and so on can be any case

Assigning a reference to a variable

<?php

$a = ' Bob ';

$b =& $a

?>

A and B as long as any one of these changes, the other will change.

Type Introduction

The type of the variable is usually not set by the programmer, rather, it is determined by the context at which PHP is used according to the variable.

If you want to see the value and type of an expression, you can use the function var-dump ()

For example

<?php

$bo =ture;

$AA = "Foo";

$in = 12;

Var-dump ($BO); Direct output variable $bo type and value bool (TRUE)

Var-dump ($AA); Direct output string (3) "Foo"

Var-dump ($in); Direct output int (12)

?>

PHP variable definition and use

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.