- Introduction to operators in PHP in Hindi
- Arithmetic Operators
- Assignment Operators
- Bitwise Operators
- Comparison Operators
- Incrementing/Decrementing Operators
- Logical Operators
- String Operators
- Array Operators
- Type Operators
- Execution Operators
- Error Control Operators

Introduction to operators in PHP
PHP operator एक symbol है जिसका उपयोग operands पर operations करने के लिए किया जाता है। सरल शब्दों में, ऑपरेटरों का उपयोग variables या values पर operations करने के लिए किया जाता है। उदाहरण के लिए:
$num=10+20;//+ is the operator and 10,20 are operands
उपरोक्त उदाहरण में, + binary + ऑपरेटर है, 10 और 20 ऑपरेंड हैं और $num variable है।
PHP operators को निम्नलिखित रूपों में वर्गीकृत किया जा सकता है:
- अंकगणितीय आपरेटर
- असाइनमेंट ऑपरेटर्स
- बिटवाइज ऑपरेटर्स
- तुलना संचालक
- बढ़ाना / घटाना ऑपरेटरों
- लॉजिकल ऑपरेटर्स
- स्ट्रिंग ऑपरेटर्स
- ऐरे ऑपरेटर्स
- संचालक टाइप करें
- निष्पादन संचालक
- त्रुटि नियंत्रण ऑपरेटर
हम operators को operands की ओर से categorise भी कर सकते हैं। उन्हें 3 forms में वर्गीकृत किया जा सकता है:
- Unary operators: single ऑपरेंड जैसे ++, — आदि पर काम करता है।
- Binary operators: दो operands पर काम करता है जैसे बाइनरी +, -, *, / आदि।
- Ternary operators: तीन ऑपरेंड्स पर काम करता है जैसे “?:”.
Arithmetic operators
PHP arithmetic operators का उपयोग संख्यात्मक values के साथ सामान्य arithmetic operations जैसे कि जोड़, घटाव आदि करने के लिए किया जाता है।
Operator | Name | Example | Explanation |
---|---|---|---|
+ | Addition | $a + $b | operands का योग |
– | Subtraction | $a – $b | operands का अंतर |
* | Multiplication | $a * $b | operands का उत्पाद |
/ | Division | $a / $b | operands का उद्धरण |
% | Modulus | $a % $b | operands का शेष |
** | Exponentiation | $a ** $b | $a raised to the power $b |
PHP 5.6 में exponentiation (**) ऑपरेटर पेश किया गया है।
Assignment operators
Assignment operators का इस्तेमाल अलग-अलग variables में वैल्यू असाइन करने के लिए किया जाता है। मूल assignment ऑपरेटर “=” है।
Operator | Name | Example | Explanation |
---|---|---|---|
= | Assign | $a = $b | दाएं ऑपरेंड का मान बाएं ऑपरेंड को सौंपा गया है। |
+= | Add then Assign | $a += $b | Addition same as $a = $a + $b |
-= | Subtract then Assign | $a -= $b | Subtraction same as $a = $a – $b |
*= | Multiply then Assign | $a *= $b | Multiplication same as $a = $a * $b |
/= | Divide then Assign (quotient) | $a /= $b | Find quotient same as $a = $a / $b |
%= | Divide then Assign (remainder) | $a %= $b | Find remainder same as $a = $a % $b |
Bitwise operators
बिटवाइज़ ऑपरेटरों का उपयोग ऑपरेंड्स पर bit-level operations करने के लिए किया जाता है। ये ऑपरेटर पूर्णांक के भीतर विशिष्ट बिट्स के मूल्यांकन और manipulation की अनुमति देते हैं।
Operator | Name | Example | Explanation |
---|---|---|---|
& | And | $a & $b | Bits that are 1 in both $a and $b are set to 1, otherwise 0. |
| | Or (Inclusive or) | $a | $b | Bits that are 1 in either $a or $b are set to 1 |
^ | Xor (Exclusive or) | $a ^ $b | Bits that are 1 in either $a or $b are set to 0. |
~ | Not | ~$a | Bits that are 1 set to 0 and bits that are 0 are set to 1 |
<< | Shift left | $a << $b | Left shift the bits of operand $a $b steps |
>> | Shift right | $a >> $b | Right shift the bits of $a operand by $b number of places |
Comparison operators
तुलना ऑपरेटर दो values की तुलना करने की अनुमति देता है, जैसे संख्या या स्ट्रिंग comparison ऑपरेटरों की सूची नीचे दी गई है:
Operator | Name | Example | Explanation |
---|---|---|---|
== | Equal | $a == $b | यदि $a $b के बराबर है तो TRUE लौटाता है |
=== | Identical | $a === $b | यदि $a $b के बराबर है, और वे समान डेटा प्रकार के हैं तो TRUE लौटाता है |
!== | Not identical | $a !== $b | TRUE लौटाता है यदि $a $b के बराबर नहीं है, और वे समान डेटा प्रकार के नहीं हैं |
!= | Not equal | $a != $b | यदि $a $b के बराबर नहीं है तो TRUE लौटाता है |
<> | Not equal | $a <> $b | यदि $a $b के बराबर नहीं है तो TRUE लौटाता है |
< | Less than | $a < $b | यदि $a $b से कम है तो TRUE लौटाता है |
> | Greater than | $a > $b | यदि $a $b से अधिक है, तो TRUE लौटाता है |
<= | Less than or equal to | $a <= $b | TRUE लौटाता है यदि $a, $b से कम या बराबर है |
>= | Greater than or equal to | $a >= $b | TRUE लौटाता है यदि $a, $b से अधिक या बराबर है |
<=> | Spaceship | $a <=>$b | -1 लौटाता है यदि $a $b से कम है तो 0 लौटाता है यदि $a बराबर $b के 1 लौटाता है यदि $a $b से अधिक है |
Incrementing/decrementing operators
Variable के मूल्य को बढ़ाने और घटाने के लिए increment और decrement ऑपरेटरों का उपयोग किया जाता है।
Operator | Name | Example | Explanation |
---|---|---|---|
++ | Increment | ++$a | Increment the value of $a by one, then return $a |
$a++ | Return $a, then increment the value of $a by one | ||
— | decrement | –$a | Decrement the value of $a by one, then return $a |
$a– | Return $a, then decrement the value of $a by one |
Logical operators
Logical ऑपरेटरों का उपयोग ऑपरेंड पर bit-level operations करने के लिए किया जाता है। ये ऑपरेटर पूर्णांक के भीतर विशिष्ट बिट्स के मूल्यांकन और manipulation की अनुमति देते हैं।
Operator | Name | Example | Explanation |
---|---|---|---|
and | And | $a and $b | यदि $a और $b दोनों सत्य हैं, तो TRUE लौटाता है |
Or | Or | $a or $b | TRUE लौटाता है यदि $a या $b सत्य है |
xor | Xor | $a xor $b | TRUE लौटाता है यदि $a या $b में से एक सत्य है लेकिन दोनों नहीं |
! | Not | ! $a | अगर $a सही नहीं है तो TRUE लौटाता है |
&& | And | $a && $b | TRUE लौटाता है यदि $a और $b सत्य हैं |
|| | Or | $a || $b | TRUE लौटाता है यदि $a या $b सत्य है |
String operators
String operators का उपयोग strings पर ऑपरेशन करने के लिए किया जाता है। PHP में दो स्ट्रिंग ऑपरेटर हैं, जो नीचे दिए गए हैं:
Operator | Name | Example | Explanation |
---|---|---|---|
. | Concatenation | $a . $b | Concatenate $a और $b दोनों |
.= | Concatenation and Assignment | $a .= $b | पहले $a और $b को concatenate करें, उसके बाद concatenated string को $a, e.g. $a = $a . $b |
Array operators
Array operators का उपयोग array के मामले में किया जाता है। मूल रूप से, इन ऑपरेटरों का उपयोग arrays के मूल्यों की तुलना करने के लिए किया जाता है।
Operator | Name | Example | Explanation |
---|---|---|---|
+ | Union | $a + $y | $a और $b का संघ |
== | Equality | $a == $b | यदि $a और $b में समान key/value pair है, तो TRUE लौटाता है |
!= | Inequality | $a != $b | यदि $a $b के बराबर नहीं है तो TRUE लौटाता है |
=== | Identity | $a === $b | TRUE लौटाता है यदि $a और $b में समान क्रम में समान कुंजी / मान युग्म हो |
!== | Non-Identity | $a !== $b | यदि $a, $b के समान नहीं है, तो TRUE लौटाता है |
<> | Inequality | $a <> $b | यदि $a $b के बराबर नहीं है तो TRUE लौटाता है |
Type operators
Type operator instanceof का उपयोग यह निर्धारित करने के लिए किया जाता है कि कोई object, उसके parent और उसके derived class एक ही प्रकार के हैं या नहीं। मूल रूप से, यह ऑपरेटर निर्धारित करता है कि ऑब्जेक्ट किस निश्चित वर्ग से संबंधित है। इसका उपयोग object-oriented प्रोग्रामिंग में किया जाता है।
Execution operators
PHP में एक execution operator backticks है (“) । PHP एक shell command के रूप में backticks की सामग्री को निष्पादित करता है। execution operator और shell_exec () एक ही परिणाम देते हैं।
Operator | Name | Example | Explanation |
---|---|---|---|
“ | backticks | echo `dir`; | Execute the shell command and return the result. यहां, यह वर्तमान फ़ोल्डर में उपलब्ध निर्देशिकाओं को दिखाएगा। |
नोट: ध्यान दें कि backticks (“) single-quotes नहीं हैं।
Error control operators
PHP में एक error control operator है, अर्थात, (@) प्रतीक पर । जब भी इसका उपयोग expression के साथ किया जाता है, तो किसी भी error message को अनदेखा कर दिया जाएगा जो उस expression द्वारा उत्पन्न हो सकता है।
Operator | Name | Example | Explanation |
---|---|---|---|
@ | at | @file (‘non_existent_file’) | Intentional file error |
PHP operators precedence
आइए PHP ऑपरेटर्स की precedence के साथ associativity देखें।
Operators | Additional Information | Associativity |
---|---|---|
clone new | clone and new | non-associative |
[ | array() | left |
** | arithmetic | right |
++ — ~ (int) (float) (string) (array) (object) (bool) @ | increment/decrement and types | right |
instanceof | types | non-associative |
! | logical (negation) | right |
* / % | arithmetic | left |
+ – . | arithmetic and string concatenation | left |
<< >> | bitwise (shift) | left |
< <= > >= | comparison | non-associative |
== != === !== <> | comparison | non-associative |
& | bitwise AND | left |
^ | bitwise XOR | left |
| | bitwise OR | left |
&& | logical AND | left |
|| | logical OR | left |
?: | ternary | left |
= += -= *= **= /= .= %= &= |= ^= <<= >>= => | assignment | right |
and | logical | left |
xor | logical | left |
or | logical | left |
, | many uses (comma) | left |