A brief introduction to the basics of PHP
PHP is the best language in the world." This sentence is familiar to everyone! It may lead to another spat. In fact, any programming language has its own advantages and disadvantages, and it can be used in different fields and different environments. It has different functions. I dare not say that PHP is the best language in the world, but I dare to say "I love PHP". I am not a big expert, but I am someone who is familiar with PHP. This article is suitable for people with some basic knowledge of PHP. It is an overview and summary. I hope it will be helpful to everyone!
PHP Introduction
PHP (foreign name: PHP: Hypertext Preprocessor, Chinese Name: "Hypertext Preprocessor") is a general open source scripting language. PHP was originally the abbreviation of Personal Home Page and has been officially renamed "PHP: Hypertext Preprocessor". It is more than 20 years old and its syntax has absorbed the C language. , Java and Perl features, easy to learn, widely used, mainly suitable for web development. PHP's unique syntax mixes C, Java, Perl and PHP's own syntax, which can execute dynamic web pages faster than CGI or Perl. . Compared with other programming languages, dynamic pages made with PHP embed programs into HTML (an application under the standard universal markup language) document for execution, and the execution efficiency is much higher than CGI that completely generates HTML tags. ; PHP can also execute compiled code. Compilation can encrypt and optimize code running, making the code run faster.
PHP Basic Syntax
# #1. Names are case sensitive
Variable names, constant names, array indexes (key names) are allcase sensitive , the names must be consistent
2. Variables, constants
Naming:
Mark variables with "$" and cannot numbers, spaces, . to start with, but can have Chinese characters, such as $variable=123;Variable variables:
$a = 'aa'; $$a = 'bb'; Then $aa = 'bb';Reference assignment:
$a='123'; $b =&$a; Quite Since $a and $b both point to a space in memory, if the value of $a is changed, $b will also change. Similar to C language &, the difference is that unset($a), $b still exists. #Variable type: Integer int, floating point float, string string, boolean, array array, object object, resource resource, empty null
Global variables: Global variables themselves are static storage methods, and all global variables are static variables
Static variables:
static
Declare it to be global)
2. Static local variables only take effect within the function body, which is relatively safe. Therefore, it is recommended to use static local variables
Static global variables are also global variables. They are at the same level as $_GET, $_POST, $_FILES and have the same storage location (as are constants)
Static method can be used directly without the class being instantiated. For example, Math::MAX($a,$b); calls the static method directly without instantiating the Math class.
Constants: define('constant name', 'constant value',$flag=false); $flag If true, it is not case-sensitive. The default is false, which is size-sensitive. Write;
Predefined constants: PHP_OS, PHP_VERSION,
E_ERROR=1 error, causing the script to terminate; E_WARNING=2 warning, the script does not terminate; E_NOTICE=8 non- Critical error Magic constants: Magic constants can be uppercase or lowercase. They are not case-sensitive. They all return the physical path. Even if they are included in the output, the output is the source code information, not the currently included file. Information, distinguished from $_SERVER. (1). __FILE__ Current file path (6). __METHOD__ In the current file Return the class name in the method in the class of the file::Method name Summary: (Global) constants: (Default constants are global) stored in the (static) data segment Variables: global variables (static data segment), local variables (stored on the stack), static variables (whether global or local are stored in the static data segment) 3. Type Conversion 1. Get the type of variable getType($a); 2. Set the type of variable setType($a,'type '); Types include boolean, integer, float, string, array, object, null ## 3. Forced type conversion, (same type as above) #Q # 四 四 Arithmetic operators: addition +, subtraction -, multiplication *, division /, modulo %, auto-increment ++, auto-decrement-- . . 'two'; then $str = 'onetwo'; Assignment operators: =, +=, -=, *=, /=, %= , .= Comparison operators: >, >=, <, <=,==, ===, !=, !===, <> Logical operators: logical AND and, &&; Logical OR or, ||; Negation not,! ; Logical XOR xor (different returns true on both sides, the same returns false) Bitwise operators: & (bitwise AND), | (bitwise OR), ^ (bitwise exclusive OR); ~ (bitwise negation); <<(bitwise left shift); > ;>(Bitwise right shift) Other cloud operators: but but 5. Process control 1. Judgment statement IF statement ## If(condition) {Statement to be executed when the condition is true} else {Statement executed when the condition is false} ## if (condition){ true, statement} elseif(condition){the second condition is true, statement}...else{false, statement};....indicates that elseif can be used multiple times. ## switch(condition) { # …. Default statement; ## } Condition){ If the condition is true, execute the statement inside; if the condition is false, exit the loop} DO...WHILE statement: do{ First time directly Execute the loop body, start for the second time, execute according to the condition if it is true, exit the loop if it is false} while (condition) ## 3 . Statement to exit the loop body continue,break;exit Difference: continue skips the current loop, the loop is still continuing break jumps out of the current loop Loop, loop termination exit; Terminate the current script, the code after this line of code will not be executed. Related recommendations: php basic knowledge note sharing
(2). __DIR__ Current file directory
(3). __LINE__ In The line of the file
(4). __FUNCTION__ In the function in the current file Returns the function name
(5). __CLASS__ In the class in the current file Returns the class name
# 4. Type conversion function
# intval(), convert to an integer; floatval(); convert to a floating point type; strval(); get the string of the variable
## 5. Determine the type
## ?: ternary operator, @ ignored Error, => Array subscript, -> Call the properties and methods of the object
## else { False, statement}
## If (condition){True, statement}
## FOR statement: for(initial value; condition; change Conditional statement) {Statement in the loop body}. Such as for($i=0; $i<8; $i++) { echo $i;}
The above is the detailed content of A brief introduction to the basics of PHP. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

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 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

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 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
