search
HomeBackend DevelopmentPHP TutorialPHP and MYSQL Programming [Fourth Edition] Chapter 3 Essay - (2), MySQL Programming_PHP Tutorial

PHP and MYSQL Programming [Fourth Edition] Chapter 3 Essay - (2), MySQL Programming

Chapter 3 PHP Basics

(3.6——3.11)

3.6 Variables

Variable declaration

Variable assignment: assignment by value/assignment by reference

Variable scope:

Local variables: Variables declared in a function can only be referenced in the function

Function parameters: Any function that accepts parameters must declare these parameters at the beginning of the function. Although these parameters accept values ​​from outside the function, they are no longer accessible after exiting the function

Parameter instancePHP and MYSQL Programming [Fourth Edition] Chapter 3 Essay - (2), MySQL Programming_PHP Tutorial//Multiply a value by 10 and return it to the caller function x10 ($value){ $value = $value * 10; return $value; } //The parameters will be revoked after the function is executed

Global variables: (use with caution)

When accessing within a function, just add the keyword global

in front of the variable

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

Static variable:

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

You can declare a static variable by adding the keyword STATIC in front of the variable name

PHP super global variables:

You can obtain detailed information about the current user session, user operating environment and local operating environment through PHP's super global variables

PHP and MYSQL Programming [Fourth Edition] Chapter 3 Essay - (2), MySQL Programming_PHP Tutorialforeach ($_SERVER as $var => $value) { echo "$var => $value
"; } //For example, display the user IP address: printf("Your IP address is: %s",$_SERVER['REMOTE_ADDR']); //You can also get information about the user's browser and operating system: printf("Your browser is: %s",$_SERVER['HTTP_USER-AGENT']); Gives all predefined variable codes related to the given web server and script execution environment

Use the GET method to obtain the passed variables

Use the POST method to get the passed variables

Get information stored in cookies:

The $_COOKIE super global variable stores the information passed to the script through the HTTP cookie

These cookies are generally set by a previously executed PHP script through the PHP function setcookie()

Use POST method to get information about uploaded files

The $_FILES super global variable includes information about the data uploaded to the server through the POST method

                          $_FILES is a two-dimensional array containing 5 elements:

                          $_FILES['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

                         $_FILES['upload-name']['size']. Size of uploaded file in bytes

                         $_FILES['upload-name']['tmp_name']. After uploading, give this file a temporary name 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. File size exceeds the maximum value specified by the MAX_FILE_SIZE hidden form field parameter (optional)

                                                                     UPLOAD_ERR_PARTIAL. Only part of the file was uploaded

                                                                                                                                                                                                                                                                             UPLOAD_NO_FILES. No file specified in file form

More about the operating system environment:

The $_ENV super global variable provides information about the server environment where the PHP parser is located

$_ENV['HOSTNAME']. Server hostname

$_ENV['SHELL']. System shell

Get information stored in the session: $_SESSION super global variable contains information related to all session variables

Variable of variable: Add a dollar sign before the original variable name, and then assign another value to it

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:

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

If the optional parameter case_insensitive is used and the value of this parameter is TRUE, then subsequent references to this constant will not be case sensitive

There is no need to use the dollar sign before constants

Once defined, a defined constant cannot be redefined or undefined.

3.8 Expression

Operand (operand): The operand is the input of the expression

Operator: An operator is a symbol that specifies an action in an expression

Operator list

Operator precedence

Operator associativity

Arithmetic operators: " ", "-", "*", "/", "%"

Assignment operators: "=", " =", "*=", "/=", ".="

String operators: "=", ".="

Self-increase and self-reduced operator: "", "-"

                                                                                                                            According to the placement position of the auto-increment and auto-decrement operators, they can be divided into front auto-increment operation, front auto-decrement operation, post-increment operation, and post-auto-decrement operation

Logical operators: "&&", "AND", "||", "OR", "!", "NOT", "XOR"

Equality operators: "==", "!=", "==="

                  Comparison operators: "", "=", "($a == 12) ? 5 : -1" (if $a is equal to 12, Return value 5; otherwise return value -1)

                 Bit operators: "&", "|", "^" (XOR. Every bit contained in $a or $b is XORed), "~ $b" (not. Every bit in $b) Bit opposite), "$a>" (shift right)

3.9 String insertion

Double quotes

Escape sequence: Description

n Line break character

r

t Horizontal tab

Backslash

                                                                                                       

single quote

Braces

heredoc syntax:

php PHP and MYSQL Programming [Fourth Edition] Chapter 3 Essay - (2), MySQL Programming_PHP Tutorialecho EXCERPT

The homepage of the blog park (i.e. the homepage of the website) can only publish original, high-quality content that readers can learn from.

EXCERPT; ?> //The start and end identifiers must be the same. The start and end identifiers here are EXCERPT, which can also be customized //The start and end identifiers can only consist of alphanumeric characters and underscores, and cannot start with numbers or underscores //There must be 3 angle brackets before the start identifier: heredoc example Nowdoc syntax

3.10 Control Structure

Conditional statements (the syntax of each statement is omitted)

if statement

else statement

elseif statement

switch statement

Loop statements (the syntax of each statement is omitted)

while statement

do...while statement

for statement

foreach statement

Break statement and goto statement

continue statement

The file contains the statement

include()

include() or include ""

Format: include(/path/to/filename)

Make sure you only include the file once: include_once()

Request file: require()

When require() fails, the script will stop executing. include() will continue to execute in this case

Make sure you only request the file once: require_once()

3.11 Summary

To become a successful PHP programmer, the foundation laid in this chapter is of extraordinary significance!

 

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1029362.htmlTechArticlePHP and MYSQL Programming [Fourth Edition] Chapter 3 Essay - (2), MySQL Programming No. Chapter 3 PHP Basics (3.63.11) 3.6 Variable variable declaration Variable assignment: assignment by value/assignment by reference...
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 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 and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

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 Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools