Operator एक symbol होते हैं , जो process / operation  represent  करते हैं करते हैं , या हम कह सकते हैं की Operators को कोई process / या operation को perform  करने के लिए use करते हैं।

Image could not load

PHP variables

ऊपर दिए गए image में Assignment Operator ( = ) use किया गया है , जो कि right side की value ( जिसे Operand कहते हैं ) को variable में assign कर रहा है।

PHP Operator Example

<?php $x = 10; $y = 20; echo $x + $y; /*here + (plus sign) is a operator , that is adding two values*/ ?>

Output :

30

ऊपर दिए गए example में आप देखा सकते हैं कि + (plus sign) Operator define की गयी दो values को add रहा है।

इसी तरह से PHP हमें different - different Operators provide कराती है different - different action perform करने के लिए। PHP में normally use होने वाले Operators कुछ इस प्रकार हैं -

  1. Arithmetic Operators

  2. Assignment Operators

  3. Comparison Operators

  4. Incrementing/Decrementing Operators

  5. Logical Operators

  6. String Operators

  7. Array Operators

  8. Conditional / Ternary Operator

PHP Arithmetic Operators

Arithmetic Operators simple calculation में use होने wale Operators होते हैं जैसे Addition , Subtraction etc .

Now assume हमने $x और $y दो variables define किये हैं तो arithmetic operator कुछ इस तरह से operation perform करेंगे।

OperatorNameExample Explanation
+Addition$x+$y( + ) plus operator uses to add two or more numbers / values
-Subtraction

$x-$y

( -  ) minus operator uses to substract one  numbers / values from another numbers / values or finds the difference
/Division$x / $yquotient of $x and $y
*multiplication$x * $yproduct of $x and $y
%Modulus$x % $yremainder of operands
**Exponentiation$x ** $y$x raised to the  power $y

Note - Exponential ( ** ) operator PHP Version 5.6 में introduce किया गया था।

PHP Assignment Operators

Assignment Operator को ( = ) से
represent करते हैं , जो कि value को किसी variable में assign करने के लिए use किया जाता है। हालाँकि इसे Arithmetic Operators के साथ भी use करते हैं। नीचे दिए गए Example में आप देख सकते हैं।

OperatorNameExample Explanation
=Assign$x = $yvalue of $y assigned to $x
+=Addition then Assign

$x += $y

First add and assign it to $x. (It is same as $x = $x+$y )
- =Subtract then Assign

$x -= $y

get the difference and assign it to $x. (It is same as $x = $x-$y )
/ =Divide then assign quotient$x /= $yquotient of $x and $y then assign it to $x . (It is same as $x = $x/$y )
* =Multiplication then assign the product$x * =$yproduct of $x and $y then assign it to $x. (It is same as $x = $x*$y )
% =Divide then assign remainder
$x %= $yremainder of operands then assign it to $x. (It is same as $x = $x+%$y )

PHP Comparison Operators

Comparison Operators दी हुई दो values को compare करके Boolean (1 for true and for false It returns nothing ) value return करते हैं according to condition . PHP में Comparison Operators को कुछ इस तरह से use कर सकते हैं।

OperatorNameExampleExplanation
==Equal$x = = $ychecks if $x is equal to $y.
===Identical

$x === $y

checks if $x is equal to $y with their data types.
!=Not equal$x != $ychecks if $x is not equal to $y.
<>Not equal$x <> $ychecks if $x is not equal to $y.
!==Not identical$x !=$ychecks if $x is not equal to $y with data types.
<Less than$x < $ychecks if $x is less than $y.
>Greater than$x > $ychecks if $x is greater than $y.
<=Less than or equal$x <= $ychecks either $x is less than or equal to $y.
>=Greater than or equal$x >= $ychecks either $x is greater than or equal to $y.

PHP Incrementing/Decrementing Operators

Incrementing/Decrementing Operators को किसी variable को 1 से increase
या decrease करने के लिए use किया जाता है। हालाँकि इसमें Addition और Subtraction operation ही होते हैं , इसलिए इसमें ( ++ ) या ( -- )  sign  ही use होते हैं। नीचे table में आप देख सकते हैं किसा तरह से इन्हे उसे करते हैं और क्या Output generate हैं।

OperatorNameExplanation
++$aPre Incrementfirst increment by 1 then return the value of $a
$a++post Incrementfirst return the value of $a then increment by 1.
--$aPre Decrementfirst decrement by 1 then return the value of $a
$a--Post Decrementfirst return the value of $a then decrement by 1.

PHP Logical Operators

Logical Operators , एक या एक से अधिक expression के according Boolean value return करते हैं। जैसे -

OperatorNameExampleExplanation
andAnd$x and $yReturns True if Both operands ($x and $y) are true;
orOr

$x or $y

Returns True if either$x or $y is true;
xorXor$x xor $yReturns True if either $x or $y is true but not both.
&&And$x && $ysame as and,returns True if Both operands ($x and $y) are true;
!Not!$xReturns True if $x is not true;
||Or$x || $ysame as or , returns True if either $x or $y is true;

PHP String Operators

PHP में दो String Operators introduce किये , 1 . concatenation operator (
. ) string concatenation के लिए और 2 . concatenating assignment - जो string को concat करने के बाद assign भी कर देता है।

OperatorNameExample Explanation
.Concatenation$x . $yConcatenate  $x and $y.
orAssignment Concatenation$x .= $yConcatenate $x and $y and then assign it to $x.

PHP Array Operators

PHP हमें array operators भी provide कराती है जिसकी help से हम directly array पर action perform कर सकते हैं।

माना हमारे पास दो array variable $x = ['key1'=>'value1', 'key2'=>'value2'] और $y = ['key1'=>'value1', 'key2'=>'value2'] हैं , तो array operators को कुछ इस तरह से use करेंगे।

OperatorNameExplanation
$x+$yUnion
union of $x and $y .
$x == $yEqualityयह true return करता है अगर दोनों array में same key value हैं , हालाँकि ( == ) में value का type match नहीं होता।
$x === $yIdentityयह true return करता है अगर दोनों array में same key value हैं , और values का type भी same है।

Example :

<?php /*define array*/ $x = array('key1'=>'value1', 'key2'=>'value2', 'key3'=> 'value3'); $y = array('key1'=>'value1', 'key2'=>'value2'); echo "Union of x and y :"; echo "<pre>"; print_r($x+$y); echo "</pre>"; /*again define array with same key value*/ $a = array('key1'=>'value1', 'key2'=>'value2'); $b = array('key1'=>'value1', 'key2'=>'value2'); echo "Equality of x and y :". ($a==$b)."<br>"; echo "Identity of x and y :". ($b===$b); ?>

Output :

Union of x and y :

Array
(
    [key1] => value1
    [key2] => value2
    [key3] => value3
)

Equality of x and y :1
Identity of x and y :1

तो आपने देखा कि किस तरह से array operators को use करते हैं।

PHP Ternary Operator

Conditional / Ternary Operator में हम ( ? : ) use करते हैं , सबसे पहले दिए गए expression / condition को evaluate करते हैं अगर expression true है तो question mark ( ? ) के बाद का statement run होगा और अगर expression / condition false है तो colon ( : ) के बाद वाला statement run होगा। । जैसे -

Example -

<?php $age = 17; $res = ($age >= 18) ? "You are able to vote" : "You are not able to vote"; echo $res; ?>

Output :

You are not able to vote 

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers