Take you two minutes to understand the operators in PHP
(1) Arithmetic operator
<?php $maxLine = 4; //每排人数 $no = 17;//学生编号 $line = ceil($no/$maxLine); // 向上取整 $row = $no%$maxLine ? $no%$maxLine : $maxLine; echo "编号<b>".$no."</b>的座位在第<b>".$line."</b>排第<b>".$row."</b>个位置";?>
(2) Assignment operator
- "=": 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, first apply for a piece of memory for the operand on the left, and then put the copied value into this memory
- "&": 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
<?php $a = "我在慕课网学习PHP!"; $b = $a; $c = &$a; $a = "我天天在慕课网学习PHP!"; echo $b."<br />"; // 我在慕课网学习PHP! echo $c."<br />"; // 我天天在慕课网学习PHP! ?>
(3) Comparison operator
<?php $a = 1; $b = "1"; var_dump($a == $b); // true var_dump($a === $b); // false var_dump($a != $b); //false var_dump($a <> $b); // false var_dump($a !== $b); // true var_dump($a < $b); //false $c = 5; var_dump($a < $c); //true var_dump($a > $c); // false var_dump($a <= $c); // true var_dump($a >= $c); // false var_dump($a >= $b); // true?>
(4) Ternary operator
- ("?:") The ternary operator is also a Comparison operator
- Expression (expr1)?(expr2):(expr3), if the value of expr1 is true, the value of this expression is expr2, otherwise it is expr3.
<?php $a = 78;//成绩 $b = $a >= 60 ? "及格": "不及格"; echo $b;?>
(5) Logical operator
(6) String linker
- Concatenation operator ("."): It returns the string obtained by appending the right parameter to the left parameter
- Concatenation assignment operator (".="): It Append the right parameter to the left parameter
<?php $a = "张先生"; $tip = $a.",欢迎您在慕课网学习PHP!"; $b = "东边日出西边雨"; $b .= ",道是无晴却有晴"; $c = "东边日出西边雨"; $c = $c.",道是无晴却有晴"; echo $tip."<br />"; echo $b."<br />"; echo $c."<br />"; ?>
(7) Error control operator
- An error control operator is provided in PHP "@", for some expressions that may cause errors during operation, we do not want to display error messages to customers when errors occur, which is not user-friendly.
- You can place @ in a PHP expression Previously, any error messages that might be generated by the expression were ignored
- If the track_error (this thing is set in php.ini) feature is activated, any error messages generated by the expression are stored in variables In $php_errormsg, this variable will be overwritten every time an error occurs, so if you want to use it, you must check it as soon as possible
- It should be noted that: the error control prefix "@" will not block parsing error information, and cannot Put it before the definition of a function or class, and it cannot be used for conditional structures such as if and foreach.
<?php $conn = @mysql_connect("localhost","username","password"); echo "出错了,错误原因是:".$php_errormsg; ?>
Thank you for reading, I hope you will benefit a lot.
This article is reproduced from: https://blog.csdn.net/sinat_35615296/article/details/78813100
Recommended tutorial: "php tutorial"
The above is the detailed content of Take you two minutes to understand the operators in 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











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,

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.

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.

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

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