PHP Operator

PHP Operator is used to perform operations on variable and values. Following are the types of Operator: PHP Arithmetic Operator PHP Arithmetic operator is used for arithmetical operations, such as addition, subtraction, multiplication etc.
Operator Description Example
 + Addition $x + $y
 - Subtraction $x - $y
 * Multiplication $x * $y
/ Division $x / $y
 % Modulus $x %$y
** Exponentiation $x ** $y
PHP Assignment Operators PHP assignment operator is used to write a value to a variable.
Operator Description Example
x=y , x=y The yvalueassign to X value $x=$y
x+=y , x=x+y Addition $x=$y+$z
x-=y , x=x-y Subtraction $x=$y-$z
x*=y , x=x*y Multiplication $x=$y+$z
x/=y , x=x/y Division $x=$y/$z
x%=y, x=x%y Modulus $x=$y%$z
PHP Comparison Operators PHP comparison operator are used to compare two values (number and string)
Operator Name Example
== Equal $x == $y
=== Identical $x === $y
!= Not equal $x != $y
<> Not equal $x <> $y
!== Not identical $x !== $y
> Greater than $x > $y
< Less than $x < $y
>= Greater than or equal to $x >= $y
<= Less than or equal to $x <= $y
PHP Increment / Decrement Operators PHP increment and decrement operator is used to increment and decrement a variable’s value.
Operator Name Description
++$x Pre-increment It Increments $x by 1, then returns $x.
$x++ Post-increment It returns $x, then increments $x by 1.
--$x Pre-decrement It decrements $x by 1, then returns $x.
$x-- Post-decrement It returns $x, then decrements $x by one.
PHP Logical Operators The PHP Operators are used to merge two or more conditional statements.
Operator Name Result
and And True if both $x and $y are true.
or Or True if either $x or $y is true.
xor Xor True if either $x or $y is true, but not both.
&& And True if both $x and $y are true.
|| Or True if either $x or $y is true.
! Not True if $x is not true.
PHP String Operators PHP string operators are used for string concatenation. Following are the String Operators
Operator Name Example
. Concatenation $txt1 . $txt2
.= Concatenation assignment $txt1 .= $txt2
PHP Array Operators PHP array operator is used to compare arrays.
Operator Name Example Result
+ Union $x + $y It is union of $x and $y.
== Equality $x == $y It returns true if $x and $y have the same key/value.
=== Identity $x === $y It returns true if $x and $y have the same key/value pairs in the same order and of the same types.
!= Inequality $x != $y It returns true if $x is not equal to $y.
<> Inequality $x <> $y It returns true if $x is not equal to $y.
!== Non-identity $x !== $y It returns true if $x is not identical to $y.

Related Topics

PHP rsort() Function

PHP rsort() Function The rsort () function in PHP is used to sort an array in reverse order i.e., highest to lowest. Syntax rsort ( array &$array [, int $sort_flags = SORT_REGULAR ] ) Parameter array(required)- This parameter represents the input array. sort_flags (optional)- This parameter is used to...

1 minute read.

PHP sscanf() Function

PHP sscanf() Function The sscanf() function in PHP parses input from a string according to a given format. Syntax sscanf ( string $str , string $format [,mixed &$arg1,$agr2,$arg++... ] ) Parameter str(required)- This parameter specifies the string to read. format(required)- This parameter specifies the format to use. The conversion specification...

3 minutes read.

WordPress Plugin

WordPress Plugin is a process used to add or extend the functionality which can be enabled or disabled, and it does not interfere with the software and its code. WordPress is lightweight and smooth...

2 minutes read.

PHP ord() Function

PHP ord() Function The ord() function in PHP converts the first byte of a string to a value between 0 and 255. This function interprets the binary value of the first byte of string as an...

1 minute read.

PHP str_split() Function

PHP str_split() Function The str_split() function in PHP splits a string into an array. String str_split ( string $string [, int $split_length = 1 ] ) Parameter string(required)- This parameter represents the input string. split_length(optional)- This parameter signifies the maximum length of the chunk. The default value is 1. Return This function...

2 minutes read.

PHP Arrays

PHP Array is usedto hold more than one value at a time.  In another words, we can say that an array stores multiple values in one single variable. Following are the...

2 minutes read.

PHP is_null() Function

The is_null() function in PHP is used to  find whether the specified variable is a null or not. It returns a Boolean value true if the parameter var is null else it returns...

1 minute read.

PHP uasort() Function

PHP uasort() Function The uasort() function in PHP sorts an array with a user-defined comparison function and maintains the index association. Syntax uasort ( array &$array , callable $value_compare_func ) Parameter array(required)- This parameter represents the input array. value_compare_func(required)- This parameter represents a string that describe a...

1 minute read.

PHP $ and $$ Variables

PHP $var variable is a normal variable that stores any value. PHP $$var variable is a reference variable that stores the value of$var inside it. Let us take an example. Example 1 <?php $x =...

1 minute read.

PHP lcfirst() Function

PHP lcfirst() Function The lcfirst() function in PHP converts the first character of a string to lowercase if that character is alphabetic. Syntax lcfirst ( string $str ) Parameter str(required)- This parameter signifies the input string. Return This function returns a string with the...

1 minute read.

PHP number_format() Function

PHP number_format() Function The number_format() function in PHP formats a number with grouped thousands. This function accepts one, two, or four parameters (not three): Syntax number_format ( float $number [, int $decimals ] )             or number_format ( float $number , int $decimals  , string $dec_point, string$thousands_sep ) Parameter number(required)- This parameter represents the number to be formatted. If...

1 minute read.

PHP settype() Function

PHP settype() Function The settype() function in PHP is used to set the type of variable var to type. Syntax settype ( mixed &$var , string $type ) Parameter var(required)- This parameter represents the variable being converted. type(required)- This parameter represents the type of variable that is needed.  The possible values of type are...

1 minute read.

PHP array_chunk() Function

PHP array_chunk() Function The array_chunk() function in PHP is used to split an array into chunks where the last chunk may contain less than size elements. Syntax array_chunk ( array $array , int $size [, bool $preserve_keys ]...

1 minute read.

PHP Constant

PHP constant is an identifier(name) for a simple value. The value does not change during the script. It starts with a letter or underscore not $ sign. The define()function is...

1 minute read.

PHP unset() Function

PHP unset() Function The unset() function in PHP is used to unset a given variable. This function destroys the specified variables. If this function is called inside any user-defined function, then it unsets the value associated with...

1 minute read.

PHP join() Function

PHP join() Function The join() function of PHP returns a string from the elements of an array. This function is an alias of the implode() function. Syntax join(separator,array) Parameter separator(Optional)- Specifies what to put between the array elements. The default...

1 minute read.

PHP Super Global Variables

There are various predefine “superglobals” in PHP. These variables can easily accessible in function or class. Following are the superglobals variables: $GLOBALS $_SERVER $_REQUEST $_POST $_GETetc. PHP $GLOBALS The “$GLOBAL” isa keyword that...

2 minutes read.

PHP array_uintersect_assoc() Function

PHP array_uintersect_assoc() Function The array_uintersect_uassoc() function in PHP calculates the intersection of arrays by comparing the data and indexes by separate callback functions. It returns an array containing all the values of the first input...

2 minutes read.

PHP key_exists() Function

PHP key_exists() Function The key_exists() function in PHP checks if the specified key or index exists in the array or not. Syntax key_exists ( mixed $key , array $array )  Parameter key(required)- This parameter represents the value to check. array(required)- This parameter signifies an input array with...

1 minute read.

PHP natcasesort() Function

PHP natcasesort() Function The natcasesort() function in PHP Sort an array using a case insensitive "natural order" algorithm while maintaining the keys. Syntax natcasesort ( array &$array ) Parameter array(required)- This parameter represents the input array. Return This parameter returns a Boolean...

1 minute read.