How to use PHP basic operators_PHP tutorial
Jul 21, 2016 pm 03:11 PM
1. Arithmetic operators: +, -, *, /, %.
2. Increment/decrement operators: such as $a++,$a--,++$a,--$a.
For example:
<?php
$a=10;
$b=5;
$c=$a++; //Assign value first, then increment. $c=$a,$a=$a+1
$d=$b--; //Assign value first, then decrement. $d=$b,$b=$a-1
echo '$a='.$a."||".'$c='.$c.'<br/> '; //$a=11,$c=10
echo '$b='.$b."||".'$d='.$d.'<br/>'; / /$b=4,$d=5
?>
<?php
$a=10;
$b=5;
$c=++$a; //Increment first, then assign value. $a=$a+1, $c=$a
$d=--$b; //Decrease first, then assign value. $b=$a-1, $d=$b
echo '$a='.$a."||".'$c='.$c.'<br/> '; //$a=11,$c=11
echo '$b='.$b."||".'$d='.$d.'<br/>'; / /$b=4,$d=4
?>
3. Comparison operator: reference document
4. Logical operators:
For example:
$a=10;$b=7;
if($a++>8 || $b++>7){ //$a++>8 is true , $b++>7 will not be executed
echo 'OK!';
}
echo 'a='.$a.'b='.$b; // Output OK, a=11,b=7
Change it
$a=10;$b=7;
if($a++>10 && $b++>7){ //$a++ >8 is false, $b++>7 This will not be executed
echo 'OK!';
}
echo 'a='.$a.'b=' .$b; // a=11,b=7
Details: and && both represent logical AND, what is their difference?
Mainly reflected in the priority
$a=false || true; //&& > = > and ;Compare false || true first, then assign value
$b=false or true; //|| > = > or ;Assign $b=false first and then compare, so the result is false
var_dump($a,$b); //bool(true) bool( false)

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

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 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
