Home >Backend Development >PHP Tutorial >PHP and MYSQL Programming Chapter 3 Essay——(2)

PHP and MYSQL Programming Chapter 3 Essay——(2)

WBOY
WBOYOriginal
2016-08-08 09:21:21871browse

Chapter 3 PHP Basics

(3.6——3.11)

3.6 Variables

Variable declaration

Variable assignment: assignment by value/reference assignment

Variable scope:

​​​​​​ Local variables: variables declared in the function, Can only be referenced in functions

Function parameters: Any function that accepts parameters must declare these parameters at the beginning of the function. Although these parameters accept values ​​outside the function, these parameters can no longer be accessed after exiting the function

Parameter instance

<span>//</span><span>把一个值乘以10并返回给调用者</span><span>function</span> x10 (<span>$value</span><span>){
    </span><span>$value</span> = <span>$value</span> * 10<span>;
    </span><span>return</span><span>$value</span><span>;
}
</span><span>//</span><span>函数执行后参数就会被撤销</span>

                                                        use using ‐           ‐       ‐                                        out out out out out out out out out out Through out out out of the function ’s

up  --                On the keyword global

                        Another way is to use PHP’s $GLOBALS array. $GLOBALS[""];

      Static variables:

       Unlike variables declared as function parameters, function parameters will be revoked when the function exits, and static variables will not lose their value when the function exits, and can also save this When you call this function again, use

to add a keyword static in front of the variable name to declare a static variable

PHP super global variable:

can obtain current user session and user operation through the super global variable of PHP, user operations, user operations Details such as the environment and the local operation environment

<span>foreach</span> (<span>$_SERVER</span><span>as</span><span>$var</span> => <span>$value</span><span>) {
    </span><span>echo</span> "<span>$var</span> => <span>$value</span> <br />"<span>;
}
</span><span>//</span><span>例如显示用户IP地址:</span><span>printf</span>("Your IP address is: %s",<span>$_SERVER</span>['REMOTE_ADDR'<span>]);
</span><span>//</span><span>还可以获得关于用户浏览器和操作系统的信息:</span><span>printf</span>("Your browser is: %s",<span>$_SERVER</span>[‘HTTP_USER-AGENT']);
Give all predetermined variable codes related to a given web server and script execution environment

Use the GET method to obtain the transmitted variables Passing variables 存 Obtain information stored in cookies:

$_Cookie Super global variables store information transmitted to the script through http cookie. These cookies are generally set by PHP scripts that previously executed PHP scripts.

                                                                                                                                                                                                                                                               ​

                                                                                                                  'upload-name']['name']. The file name of the file uploaded from the client to the server

                      $_FILES['upload-name']['type']. The MIME type of the uploaded file. Whether this variable is assigned a value depends on the browser's capabilities

                                                                                                                   The size of the uploaded file (in bytes)

                                                                                                              $_FILES['upload-name']['tmp_name']. After uploading, move this file to the temporary name given before moving it to its final location

                    $_FILES['upload-name']['error']. Upload status code. 5 possible values:

                                                                       UPLOAD_ERR_OK. File uploaded successfully

                                  UPLOAD_ERR_INI_SIZE. The file size exceeds the maximum value set by the upload_max_filesize directive

           UPLOAD_ERR_FORM_SIZE. The file size exceeds the maximum value specified by the MAX_FILE_SIZE hidden form field parameter (optional). The file only uploads a part of the upload_no_files. No file specified in the file form

                                                                                                                                                                                                              ​']. Server host name

                                                                                             System shell

Get the information stored in the session: $ _ session Super global variables contain information related to all session variables

Variables: Add a US dollar in front of the original variable, and then give it another value

3.7 3.7 Constants

      Constants refer to values ​​that cannot be modified in the program

          The define() function defines a constant by assigning a value to a variable name. Its form is as follows:

                                                                                                                                                                                  use using boolean define(string name, mixed value [, bol case_insensitive])

C If you use optional parameters case_insensitation, and the value of this parameter is True, then the reference to this constant will not be distinguished from the case. constant. ​​​​Operator precedence Class

operating symbol binding

calculation operator: "+", "-", "*", "/", "%"

assignment operator: "=", "+=", "*= = "/=", ". ="

string operator: "=", ". ="

self-increase and self-reduction operator: "++", "-" The placement positions of the and decrement operators are divided into pre-increment operation, pre-decrement operation, post-increment operation, and post-decrement operation. Logical operators: "&&", "AND", "||", "OR", "!", "Not", "xor"

: "==", "! =", "==="

Comparison operator: "& lt;", "& gt;", "& lt ;=", ">=", "($a == 12) ? 5 : -1" (if $a is equal to 12, return value 5; otherwise return value -1)

                位操作符:"&"、"|"、"^"(异或。$a或$b包含的每一位相异或)、"~ $b"(非。$b中的每一位相反)、"$a<<$b"(左移。把$a的位左移$b步)、">>"(右移)

    3.9 字符串插入

        双引号

        转义序列:  描述

            \n    换行符

            \r    回车

            \t    水平制表符

            \\    反斜杠

            \$    美元符

        单引号

        大括号

        heredoc语法:

<?<span>php
    </span><span>echo</span> <<<<span>EXCERPT
    </span><p>博客园首页(即网站首页)只能发布原创的、高质量的、能让读者从中学到东西的内容。</p><span>EXCERPT;
</span>?>

<span>//</span><span>开始和结束标识符必须相同。这里的开始和结束标识符是EXCERPT,也可以自定义
//开始和结束标识符只能由字母数字字符和下划线组成,而且不能以数字或下划线开头
//开始标识符前面必须有3个尖括号:<<<
//结束标识符必须在一行开始处,前面不能有任何空格或其它多余字符
//开始和结束标识符后面的任何空格都会造成语法错误</span>
heredoc实例

        Nowdoc语法

    3.10 控制结构

        条件语句(各语句语法省略)

            if语句

            else语句

            elseif语句

            switch语句

        循环语句(各语句语法省略)

            while语句

            do……while语句

            for语句

            foreach语句

            break语句和goto语句

            continue语句

        文件包含语句

            include()

                include()或include ""

                形式:include(/path/to/filename)

            确保只包含文件一次:include_once()

            请求文件:require()

      require()出错时,脚本将停止执行。include()在此情况下将继续执行

            确保只请求文件一次:require_once()

    3.11 小结

            要成为成功的PHP程序员,这一章所打下的基础有着非凡的意义!

以上就介绍了PHP与MYSQL程序设计 第三章随笔——(2),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn