Stupid birds Learn PHP (ii) How to use variables

Source: Internet
Author: User

I. Declaration of variables

1. methods of declaring variables in PHP: $var = 123;

2. PHP is a weakly typed language, and the type of the variable is determined by the stored value

Note: Java is a strongly typed language, declaring a variable must first specify the type

3. Isset () and unset ()

Isset (): Determine whether the value exists; Unset (): Remove the value of the variable

<?php $a = $b = $c = $d = "Hello, world"; unset ($a); if (Isset ($a)) {echo $a;} else{echo "not exists";}? >

Two. Naming of variables

1. be sure to use "$" before the variable, declare and use this symbol.

2. You cannot start with a number.

3. Cannot use the arithmetic symbol in PHP +-*/% &

4. You can use the System keyword as the variable name

5. Only variables and constants in PHP are case-sensitive, others do not differentiate


Two. Variable variable

1. variable names for a variable can be set and used dynamically

<?php$one = "AAA"; $two = "one"; $three = "one"; Echo $$ $three;    The result is aaa?>
2. Variable can be referenced assignment (and a reference in Java)

<?php$one = "AAA"; $two = & $one;   With the "&" symbol added to the variable that will be assigned, $one and $two point to the same address $two = "BBB"; Echo $one;? >

Three. Types of variables

1. As mentioned earlier, PHP is a weakly typed language, and its type is determined by the stored value

2. PHP has 8 types:

2.1) Four kinds of scalars:

Shape: int integer Boolean: bool Boolean float: float double real string: string

2.2) Two types of composite

Array: Array object: Object

2.3) Special types in two

Resource type: Resource NULL type: null

<?php$var=10;var_dump ($var); Int (Ten) $var =34.5;var_dump ($var); Float (34.5) $var = "abc"; Var_dump ($var); String (3) "ABC" $var =true;var_dump ($var); BOOL (true) $var =array, Var_dump ($var); Array (3) {[0]=>int (1) [1]=>int (2) [2]=>int (3)} $var =new mysqli ("localhost", "root", "root", "newcms"); var_ Dump ($var); Object (mysqli) #1 (0) {} $var =fopen ("1.php", "R"), Var_dump ($var); Resource (3) of type (stream) $var =null;var_dump ($var); Null?>

Four. Variable declarations of various types

The maximum value of <?php//integer is 4 bytes, 2 of 32 times, 214483647$int=10;   Decimal statement $int=045;  The expression starting with 0 declares a variable $int=0xff in 8 notation; The representation beginning with 0x or 0X declares a variable 0-9 a-f 0X a-f$int=-5 in 16 notation;   $float =10, $float =-10, $float =3.14e5; $float =3.15e+5; $float =5.14e-2;  E can be uppercase or lowercase//the following is false case $bool=false;   true$bool=0;       Number of $bool=0.000 not 0;   There are not 0 of the number appearing $bool= "";      $bool = "";     $bool =null;    Non-null representative $bool= "0";     Non-null non-0 string $bool=array (); There are members of the array//Expression true: True, not 0 of the number, there are non-0 of the number of occurrences, non-null represents, non-null non-0 string, there are a number of members of the array//string declaration There are several ways//1. Both single and double quotes can declare strings, and the declared string has no length String, you can directly parse the variable, or you can directly use the escape character//3. In a single-quoted string, you cannot parse a variable, or you can use an escape character (you can escape the single quotation mark itself, or you can escape the escape character "\")//4. Double quotes are no longer used in double quotes. Single quotes can no longer be used in single quotes $str= ' aaaaa\ ' aaa '; $str = "aaaa\" AAAA "; $str =<<<one one; $str = ' dir ';? >






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.