PHP operator Knowledge points

Source: Internet
Author: User
Tags arithmetic operators logical operators php operator

An expression

Almost anything written is an expression, but the simplest and most precise way to define an expression is "anything that has value."

Arithmetic operators

Commonly used in PHP are: + 、-、 *,/,% (modulo, get the remainder)

Left +-*/% a+=3 equivalent to a=a+3 other in turn

comparison Operators

$a = = $b equals True if $ A equals $b

$a = = = $b Congruent true if $ A equals $b, and their type is the same

$a! = $b Unequal to True if $ A is not equal to $b

$a <> $b True if $ A is not equal to $b

$a!== $b non-congruent true if $ A equals $b, or their type is not the same

$a < $b less than true if $ A is strictly less than $b

$a > $b greater than True if $ A is strictly greater than $b

$a <= $b less than or equal to true if $ A is less than or equal to $b

$a >= $b greater than or equal to true if $ A is greater than or equal to $b

logical Operators

$a && $b and logic and true if $ A and $b are true

$a | | $b or logic, or true if $ A and $b any one, the result is true

! $a not logical not if $ A is not true, the result is true

Ternary operators

Basic syntax:

Expression 1? Expression 2: Expression 3

Rule: If the operation result of expression 1 is true, take the value of expression 2, otherwise take the value of expression 3, the expression 2,3 can be a specific value or a formula or function.

String operators

There are 2 string operators, using the Join operator ("." ), a small dot.

<?php

$a =hello;

$b =world;

$c = $a. $b;

Echo $c;

?>

Then output: Hello World

“.” Both sides, regardless of whether it is a string, as long as "." will be processed by the type of the string, and their contents are stitched up.

type operator

Basic syntax: instanceof is used to determine whether a PHP variable belongs to an instance of a class, and in actual development we may need to determine whether a variable is a type, which is often used in object-oriented development. "The back is fine."

precedence level of operators  

rank from low to high  

PHP operator Knowledge points

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.