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

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

Aug 08, 2016 am 09:21 AM
files include nbsp php

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>
Copy after login

                                                        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']);
Copy after login
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>
Copy after login
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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles