PHP Review Basics

Source: Internet
Author: User

    1. Variable names are case-sensitive ($y and $Y are two different variables)
    2. Both the PHP statement and the PHP variable are case-sensitive.
    3. PHP does not have a command to declare variables. The variable is created when you assign it to it for the first time.
    4. Four scopes: local, Global, static, parameter
      Global calls out-of-function globally variable
      ```
      <?php

$x = 5; Global variables

function MyTest ()
{
Global $x;
$y = 10; Local variables
echo "

To test variables within a function:

";
echo "Variable x is: $x";
echo "
";
echo "Variable y is: $y";
}

MyTest ();

echo "

To test an out-of-function variable:

";
echo "Variable x is: $x";
echo "
";
echo "Variable y is: $y";

5.  PHP 将所有全局变量存储在一个名为 $GLOBALS[index] 的数组中。 index 保存变量的名称。这个数组可以在函数内部访问,也可以直接用来更新全局变量。

$x = 5; Global variables
$z = 3;

function MyTest ()
{
$GLOBALS [' z '] = $GLOBALS [' x '] + $GLOBALS [' Z '];
}
echo "Variable z is: $z";

6. 第一次声明变量时使用 static 关键字:

function MyTest ()
{
static $x = 0;
echo $x;
$x + +;
}

MyTest ();
MyTest ();
MyTest ();
Each time the function is called, the variable retains the value of the function before it was called.
The variable is still a function local variable.

7. echo 输出数组的某个值,要把有数组的变量放在{}内

$cars = Array (' Vo ', ' bmw ', ' xxx ');
echo "{$cars [0]}";

8. echo(): 可以一次输出多个值,多个值之间用逗号分隔。echo是语言结构(language construct),而并不是真正的函数,因此不能作为表达式的一部分使用。print(): 函数print()打印一个值(它的参数),如果字符串成功显示则返回true,否则返回false。print_r(): 可以把字符串和数字简单地打印出来,而数组则以括起来的键和值得列表形式显示,并以Array开头。但print_r()输出布尔值和NULL的结果没有意义,因为都是打印"\n"。因此用var_dump()函数更适合调试。var_dump(): 判断一个变量的类型与长度,并输出变量的数值,如果变量有值输的是变量的值并回返数据类型。此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值。数组将递归展开值,通过缩进显示其结构。关于echo与print的理解,echo只是打印,print有返回值。这样通过print打印后,应该可以通过一些高级操作接收返回值来进行判断吧。
function jj(){    $a=1;    echo $a;}$b=jj();var_dump($b);

Printing is only displayed on the screen, if you use this value, you must return with return in order to receive it elsewhere. So here your function doesn't return anything, it just prints 1, so variable b doesn't get any value, so it's empty.

9. php数据类型:String/Integer/Float/Boolean/Array/Object/NULL10. define 定义常量:后面有true为不区分大小写,默认为false区分大小写。define("GREETING", "欢迎访问 Runoob.com", true);11. 字符串操作http://www.runoob.com/php/php-ref-string.html12. php逻辑运算符:

An XOR operation that returns True if X and Y have and only one is true.
XOR operations and OR operations
$x = 6;
$y = 3;
Var_dump ($x xor $y);//false
Var_dump (False Xor $y);//true
Var_dump (False or $y);//true

Priority: && > = > and
Priority level: | | > = > or

"| |" has higher precedence than "or"

The result of an expression (false | | true) is assigned to the $e
Equivalent to: ($e = (false | | true))
$e = False | | True

Constant false is assigned to $F, true is ignored
Equivalent to: (($f = false) or True)
$f = False or true;

Var_dump ($e, $f);

// --------------------
"&&" is higher priority than "and"

The result of an expression (true && false) is assigned to the $G
Equivalent to: ($g = (true && false))
$g = True && false;

Constant true is assigned to $h, false is ignored
Equivalent to: (($h = True) and false)
$h = True and false;

Var_dump ($g, $h);
```

    1. When iterating through a numeric array with a For loop, the for () condition in parentheses uses a semicolon , not a comma. Iterate through the associative array using foreach.
      Array Manipulation http://www.runoob.com/php/php-ref-array.html
    2. PHP in $_request, $_post, $_get. $_request both can receive, but slower than the two.

PHP Review Basics

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.