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 array_intersect_key() function

The array_intersect_key () function in PHP is used to compute the intersection of arrays using keys for comparison. It returns an array containing all the entries from array1 which have keys that are present in...

1 minute read.

PHP array_diff_uassoc() Function

PHP array_diff_uassoc() Function The array_diff_uassoc () Function in PHP is used to compare the keys and values of two (or more) arrays and returns the differences (an array containing the entries from the first array that...

1 minute read.

PHP serialize() Function

PHP serialize() Function The serialize() function in PHP is used to convert a storable representation of a value. Syntax serialize ( mixed $value ) Parameter value(required)- This parameter represents the value to be serialized. Return This function returns a string containing a byte-stream representation...

1 minute read.

PHP Forms

PHP form is used to take input from users, by using superglobals$_REQUEST, $_GET and $_POSTmethod. There are various request methods in PHP Get method Post method Put method Patch method Delete...

5 minutes read.

PHP fprintf() Function

PHP fprintf() Function The fprintf() function in PHP outputs a formatted string. This function operates as printf() but accepts an array of arguments, rather than a variable number of arguments. Syntax vprintf ( string $format , array $args ) Parameter format(required)- This parameter specifies the string and how to...

4 minutes read.

PHP array_multisort() Function

PHP array_multisort () Function The array_multisort() function in PHP sorts multiple or multi-dimensional arrays at once. Syntax array_multisort ( array &$array1 [, mixed $array1_sort_order [, mixed $array1_sort_flags [, mixed $... ]]] ) Parameter array1(required)- This parameter specified the input array to sort. array1_sort_order(optional)- This parameter specifies the order (ascending or descending)...

1 minute read.

PHP Echo And Print

In PHP, echo and print is used to get output data to the screen but there is some difference, between echo and print. PHP echo PHP echo is used to display the...

1 minute read.

PHP usort() Function

PHP usort() Function The usort() function in PHP sorts  array by values using a user-defined comparison function. Syntax usort ( array &$array , callable $value_compare_func ) array(required)- This parameter represents the input array. value_compare_func(required)- This parameter represents a string that describe a callable comparison function. The comparison...

1 minute read.

PHP crc32() Function

PHP crc32() Function The crc32() function in PHP  Calculates the crc32 polynomial of a string. Syntax crc32( string $str ) Parameter str(required)- This parameter represents The string to be calculated Return This function returns the crc32 checksum of string as an integer. Example 1 ...

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 array_diff_assoc() Function

PHP array_diff_assoc() Function The array_diff_assoc() Function in PHP compares the difference of arrays and returns an array containing all the values from array1 that are not present in any of the other arrays. Syntax array_diff_assoc ( array $array1 , array $array2 [, array $... ] ) Parameter array1(required)- This parameter signifies...

1 minute read.

PHP strnatcasecmp() Function

PHP strnatcasecmp() Function The strnatcasecmp() function in PHP compares two strings using a "natural" algorithm. It is a case-insensitive function. Syntax strnatcasecmp ( string $str1 , string $str2 )  Parameter str1(required)- This parameter represents the first string. str2(required)- This parameter represents the second string. Return This function returns a value less...

1 minute read.

PHP sort() Function

PHP sort() Function The sort() function in PHP sorts an array where the elements will be arranged from lowest to highest. Syntax sort ( array &$array [, int $sort_flags = SORT_REGULAR ] )  Parameter array(required)- This parameter represents the input array. sort_flags (optional)- This parameter is used to modify the...

1 minute read.

PHP For Loops

PHP for loop is used when the specified condition is predefined. Syntax: for (initialization; condition; increment/decrement ) { code to be executed; } Example <!DOCTYPE html> <html> <head> <title>PHP Tutorial</title> </head> <body> <?php echo " Print counting using for loop"."<br>"; for($i=1;$i<=5;$i++){ echo $i."<br>"; } ?> </body> </html> Output Print counting using...

1 minute read.

PHP array_merge() Function

PHP array_merge() Function The array_merger() Function in PHP merges the elements of one or more arrays wherein the values of one are appended to the end of the previous one. It returns the resulting array...

1 minute read.

PHP MySQL Database Tutorial

MySQL is the most popular database system that is used within PHP. Let's first understand about MySQL. What is MySQL? MySQL is open-source Relational Database Management System (RDMS). The name of MySQL is...

13 minutes read.

PHP Include Function

PHP Include( ) The PHP include() statement holds all the code/text that liesin the defined file and paste it into the file that uses the "include" statement. With the help of include...

3 minutes read.

PHP in_array() Function

PHP in_array() Function The in_array() function in PHP checks if the value exists in the specified array or not. Syntax in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )  Parameter needle(required)- This parameter represents the searched value. haystack(required)- This parameter represents the input array. strict(optional)- This parameter...

1 minute read.

PHP array_push() Function

PHP array_push() Function The array_push() function in PHP pushes one or more elements onto the end of the array. This function increases the length of the array by the number of variables pushed. Syntax array_push ( array &$array, mixed& value [, mixed $... ]...

1 minute read.

PHP count_chars() Function

PHP count_chars() Function The count_chards() function in PHP is used to return information about characters in a string. Syntax count_chars ( string $string [, int $mode = 0 ] ) Parameter string(required)- This parameter represents the string to be checked. mode(optional)- It specifies the return modes Return This function returns one...

2 minutes read.