Home Backend Development PHP Tutorial How to use PHP basic operators_PHP tutorial

How to use PHP basic operators_PHP tutorial

Jul 21, 2016 pm 03:11 PM
a++ php Instructions back Base of arithmetic self-increasing Assignment operator Decreasing Increment

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

and the priority of
and< = <&&
or < = < ||
For example:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326905.htmlTechArticle1. Arithmetic operators: +, -, *, /, %. 2. Increment/decrement operators: such as $a++,$a--,++$a,--$a. Such as: ?php $a=10; $b=5; $c=$a++; //First Assigned a value, it will be incremented later. $c=$a,$a=$a+1 $d=$b--;...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

See all articles