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

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version
SublimeText3 Linux latest version
