


PHP Reading Notes (4)-Operator, PHP Reading Notes Operator_PHP Tutorial
PHP Reading Notes (4) - Operator, PHP Reading Notes Operator
What is an operator
What is an operator? Operators are identifiers that tell PHP to perform related operations. For example, if you need to calculate the value of 123 times 456, you need a symbol to tell the server that you need to do multiplication.
What are the operators in PHP? PHP operators are generally divided into arithmetic operators, assignment operators, comparison operators, ternary operators, logical operators, string concatenation operators, and error control operators.
Arithmetic operators in PHP
Arithmetic operators are mainly used for arithmetic operations, such as addition, subtraction, multiplication, and division. The commonly used arithmetic operators in PHP correspond to the following table:
Assignment operator in PHP
There are two assignment operators in PHP, namely:
(1) "=": Assign the value of the expression on the right to the operand on the left. It copies the value of the expression on the right and gives it to the operand on the left. In other words, a memory is allocated for the operand on the left first, and then the copied value is placed in this memory.
(2) "&": reference assignment, which means that both variables point to the same data. It will cause two variables to share a piece of memory. If the data stored in this memory changes, the values of both variables will change.
Comparison operators in PHP
Comparison operators are mainly used for comparison operations, such as: equal, congruent, not equal, greater than, less than. The commonly used comparison operators in PHP are as follows:
Ternary operator in PHP
("?:") The ternary operator is also a comparison operator. For the expression (expr1)?(expr2):(expr3), if the value of expr1 is true, then the value of this expression is expr2, otherwise expr3.
("?:") The ternary operator is also a comparison operator. For the expression (expr1)?(expr2):(expr3), if the value of expr1 is true, then the value of this expression is expr2, otherwise expr3.
Logical operators in PHP
Logical operators are mainly used to perform logical operations, such as logical AND, logical OR, logical XOR, logical NOT, etc. The commonly used logical operators in PHP are as follows:
We can understand logical operations from the perspective of voting:
1. Logical AND: Requires everyone to vote to agree before an agreement can be passed;
2. Logical OR: Only one person is required to vote for approval;
3. Logical XOR: Only one and only one person can vote to agree;
4. Logical negation: Someone wants to object, but through logical negation, the objection is invalid;
The reason why "AND" and "OR" have two different forms of operators is the priority of their operations (that is, the limited order of operations. For example, when we were in elementary school, we learned the four arithmetic operations, and addition, subtraction, multiplication and division were mixed together. La, it is different to calculate multiplication and division first, then addition and subtraction).
We can understand logical operations from the perspective of voting:
1. Logical AND: Requires everyone to vote to agree before an agreement can be passed;
2. Logical OR: Only one person is required to vote for approval;
3. Logical XOR: Only one and only one person can vote to agree;
4. Logical negation: Someone wants to object, but the objection is invalidated through logical negation;
String concatenation operator in PHP
The string concatenation operator is used to concatenate two strings. The string concatenation operators provided in PHP are:
(1) Concatenation operator ("."): It returns the string obtained by appending the right parameter to the left parameter.
(2) Connection assignment operator (“.="): It appends the right parameter to the left parameter.
Error control operators in PHP
PHP provides an error control operator "@". For some expressions that may go wrong during operation, we do not want to display error messages to customers when errors occur, which is not user-friendly. . Therefore, @ can be placed before a PHP expression, and any error messages that may be generated by the expression will be ignored;
If the track_error feature (this thing is set in php.ini) is activated, any error information generated by the expression is stored in the variable $php_errormsg. This variable will be overwritten every time an error occurs. So you must check it out as early as possible if you want to use it.
It should be noted that the error control prefix "@" will not block parsing error information. It cannot be placed before the definition of a function or class, nor can it be used in conditional structures such as if and foreach.
Previous article: PHP Reading Notes (3) - Constants
Next article: PHP reading notes ( 5) - Structural statement
The reason why "AND" and "OR" have two different forms of operators is the priority of their operations (that is, the limited order of operations. For example, when we were in elementary school, we learned the four arithmetic operations, and addition, subtraction, multiplication and division were mixed together. La, it is different to calculate multiplication and division first, then addition and subtraction).

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

AI Hentai Generator
Generate AI Hentai for free.

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



Introduction to python operators Operators are special symbols or keywords used to perform operations between two or more operands. Python provides a variety of operators covering a wide range of uses, from basic mathematical operations to complex data manipulation. Mathematical operators Mathematical operators are used to perform common mathematical operations. They include: operator operation examples + addition a + b - subtraction a-b * multiplication a * b / division a / b % modulo operation (take the remainder) a % b ** power operation a ** b // integer division (discard the remainder) a//b Logical Operators Logical operators are used to concatenate Boolean values and evaluate conditions. They include: operator operations examples and logical and aandbor logical or aorbnot logical not nota comparison operations

What are the logical operators in Python? Logical operators in Python are used to logically compare expressions and return a Boolean value (True or False). There are three commonly used logical operators in Python: and, or and not. and operator and operator is used to check whether all operands are true (True). The and operator returns True only if all operands are true; otherwise it returns False. Here is a sample code: a=10b=

The Secret Garden of Operators Python operators are symbols or keywords used to perform various operations. They enable developers to express complex logic concisely and clearly and improve code efficiency. Python provides a wide range of operator types, each with its specific purpose and usage. Logical Operators Logical operators are used to combine Boolean values and perform logical operations. The main ones are: and: Returns the Boolean value True, if all operands are True, otherwise it returns False. or: Returns a Boolean value True if any operand is True, otherwise returns False. not: Negate the Boolean value, change True to False, and change False to True. Demo code: x=Truey

Python operators are a key component of the programming language, enabling developers to perform a wide range of operations, from simple arithmetic to complex bit manipulation. Mastering the syntax, semantics, and functionality of operators is essential to using Python effectively. Arithmetic Operators Arithmetic operators are used to perform basic arithmetic operations. They include addition (+), subtraction (-), multiplication (*), division (/), modulo (%), exponentiation (**), and floor division (//). The following example demonstrates the use of arithmetic operators: >>a=10>>b=5#Addition c=a+bprint(c)#Output: 15#Subtraction c=a-bprint(c)#Output: 5#Multiplication c=a*bprint(c)#output

Title: How to correctly use the logical OR operator || in C language. In C language, the logical OR operator || is a commonly used logical operator, which is used to determine whether any of the conditions is true. Proper use of logical OR operators can help us write more concise and efficient code. The following will introduce in detail how to correctly use the logical OR operator || in C language and provide specific code examples. The basic syntax of the logical OR operator || is: expression 1 || expression 2. When either expression1 or expression2

Application of Advanced Python Operators: Practical Guide to Shift Operators, Logical Operators, and Operator Priority Python is a high-level programming language widely used in various fields, and it is very important to master the use of operators. In addition to basic arithmetic operators, Python also provides many other types of operators, including bitwise operators, logical operators, etc. This article will delve into the application of these operators and provide specific code examples to help readers better understand and use them. 1. Bit shift operator bits

Python operators are special symbols or words used to perform specific operations on values or to combine values. They are the fundamental building blocks of programming languages and are key to understanding and writing efficient code. Arithmetic Operators Arithmetic operators are used to perform basic mathematical operations such as addition, subtraction, multiplication, division, and remainder. The following are the most commonly used arithmetic operators: +Addition-Subtraction*Multiplication/Division%Remainder Example: x=10y=5print(x+y)#Output: 15print(x-y)#Output: 5print(x*y)#Output :50print(x/y)#Output: 2.0print(x%y)#Output: 0 Comparison Operator The comparison operator is used to compare two values and return a Boolean value (True

JavaRegularexpressionssupports3logicaloperatorstheyare−XY:XfollowedbyYX|Y:XorY(X):capturinggroup.XY:XfollowedbyYThissimplymatchestwosingleconsecutivecharacters.Example LiveDemoimportjava.util.Scanner;importjava.util.regex.Matcher;i
