


Detailed explanation of PHP variable definition and scope code examples
Mar 13, 2017 pm 04:35 PM1. php When calling attribute in a method, you cannot use echo directly. In the class, you must use $thisobject
1, PHP variable Definition and use: Letters starting with an underscore ^[a-zA-Z_]\w*2, Scope of PHP variable: Local scope: in FunctionVariables defined within the function can only work inside the function
‐ ’ down to ‐ ‐ ‐ ‐ ‐ ‐ global scope: global $var
1 |
|
Pass by reference): 1. Pass by value: # 4.
Super global variables(predefined variables): ① $GLOBALS Save global variables
② $_SERVER Save
ServiceInformation③ $_GET Save get data
④ $_POST Save post data
⑤ $_
FILECOOKIESave the obtained cookie
⑦ $_SESSION Save the session data⑧ $_REQUEST Save the request data
⑨ $ _ENV Save environment
2.##define() function can define constants
defined () Determine whether a constant is defined Features: (1) There is no need to use $ to define a constant (2) Constants do not care about the scope, they can be Useanywhere (3) Once a constant is defined, it cannot be copied again
Magic constant(7):
FILE Get the absolute path and file name of the current fileLINE The current line number of the file3. Control structure
## 1,
return;
(1) Use return in the function to immediately stop the execution of the function and return the value of the function; (2) In the php script Used in, stop the execution of script file code
2, require_once()
has the same effect as require(), both introduce external files, the difference is require_once() , if the file has already been included, it will not be included again to avoid function redefinition and variable reassignment
3. The difference between include() and require() is that include() )RepeatWhen including files, a warning level error is generated; require() generates a fatal error
4. Passing of functionparameters, default It is also a value transfer. Even if the value of the parameter is modified inside the function, it will not affect the value outside the function.
If you want to affect the transfer by reference, the reference is the value saved by this variable in the memory space5. PHP’s
1. Scalar type
1,字符串的定义
单引号:单引号会将内容原封不动的输出---执行速度快
双引号 (比较):双引号会解析变量---执行速度慢
2,常用的字符串函数(重点)
查找:
1 2 3 4 5 |
|
替换:
1 2 3 4 5 6 7 8 9 |
|
比较:
1 2 3 |
|
拆分:
1 2 3 4 5 6 7 |
|
3,正则表达式匹配:
1 2 3 4 5 6 7 8 9 |
|
整型
布尔型
2,复合类型
数组:
1, 数组的定义 array() 或 []
2,遍历数组(重点)
(1)使用for()遍历数组,适合下标从0开始,连续的整型索引数组
1 2 3 4 5 6 7 8 9 10 11 |
|
3,数组指针
(1)current()获得当前数组指针指向的数组元素
(2)next() 将数组的指针指向下一个
(3)prev() 将数组的指针向前移动一个
(4)reset() 重置数组指针
(5)end() 将数组指针移动到最后
4,常用的数组函数
array_push() 入栈,讲一个或多个元素压入数组的末尾
array_pop() 出栈,将数组最后一个元素弹出
array_shift() 将数组开头的元素移出
array_unshift() 在数组开头插入一个元素
对象
3,特殊类型
The above is the detailed content of Detailed explanation of PHP variable definition and scope code examples. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
