Learn PHP


Operator


Operators are used to perform operations on variables and values.


The basic function of an operator is to do something with the value of a variable. That “something” can be to assign a value, change a value, or compare two or more values.


PHP Assignment Operators


The assignment operators set the values of variables either by copying the value or copying a reference to a value.


The PHP assignment operators are used with numeric values to write a value to a variable.


The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.


Operator Name Description
x = y x = y The left operand gets set to the value of the expression on the right
x =& y Reference $x =& $y set $a to reference $b
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus

Example


			<?PHP
			$x = 4;
			$x = $x + 4;

			print $x;
			?>
		

Example


			<?PHP
			  $Count = 0;
			  $Count = $Count + 5;

			  //Add 5 to Count
			  $Count = 0;
			  $Count += 5;

			  //prints 13
			  print($a = $b = 13);
			  print("<br>\n");

			  //prints 7
			  $Count = 2;
			  print($Count += 5);
			  print("<br>\n");
			?>
		


Example


			<?PHP
				$a = 10;  
			    echo $a;
			?>
		

Example


			<?PHP
				$a = 20;  
				$a += 100;

				echo $a;
			?>
		

Example


			<?PHP
				$a = 50;
				$a -= 30;

				echo $a;
			?>
		

Example


			<?PHP
				$x = 10;  
				$y = 6;

				echo $x * $y;
			?>
		

Example


			<?PHP
				$x = 10;
				$x /= 5;

				echo $x;
			?>
		

Example


			<?php
				$x = 15;
				$x %= 4;

				echo $x;
			?>
		



PHP Tutorials


Home

Introduction

Syntax

Variable

Comment

Echo and Print Statement

Data Types

Boolean

Integer

Number Convert

PHP String

php variable substitution in string

php string element

php string function

php addcslashes function

php addslashes function

php get magic quotes gpc function

php get meta tags function

php urlencode function

PHP $ and $$ Variables

PHP constant

PHP Magic Constants

PHP Static Variable

PHP Super Globals

PHP Globals

PHP Server

PHP reserved variable get

PHP reserved variable post

PHP reserved variable FILES

PHP reserved variable Cookies

PHP reserved variable Session

PHP reserved variable Request

PHP reserved variable environment

PHP Operator

PHP Arithmetic Operator

PHP Comparison Operator

PHP Incrementing and Decrementing Operators

PHP Identical Operators

PHP Logical Operators

PHP String Operators

PHP Ternary Operators

PHP Execution Operators

PHP Operator Precedence

PHP Array Operator

PHP Class

PHP Class Inheritance

PHP constructor and destructor

PHP abstract class

PHP class access control

PHP statement

PHP If statement

PHP else statement

PHP else if statement

PHP control structure statement

PHP while loop

PHP do while loop

PHP for loop

PHP for each loop

PHP break statement

PHP continue statement

PHP declare statement

PHP return statement

PHP require statement

PHP include

PHP require once

PHP include once

PHP goto statement

PHP function

PHP function parameter

PHP function scope

PHP array

PHP array operator

PHP array element loop

PHP array foreach loop

PHP array multidimensional

PHP html forms

PHP get and post method

form redirect

file inclusion

file i/o