পিএইচপি অপারেটর
পিএইচপি অপারেটর হল একটি প্রতীক, যা অপারেন্ডে অপারেশন করতে ব্যবহৃত হয়। সহজ কথায়, অপারেটরগুলি ভেরিয়েবল বা মানগুলির উপর ক্রিয়াকলাপ সম্পাদন করতে ব্যবহৃত হয়। উদাহরণ স্বরূপ:
উপরের উদাহরণে, + হল বাইনারি + অপারেটর, 10 এবং 20 হল অপারেন্ড এবং $num হল পরিবর্তনশীল।
পিএইচপি অপারেটরদের নিম্নলিখিত ফর্মগুলিতে শ্রেণীবদ্ধ করা যেতে পারে:
- Arithmetic Operators
- Assignment Operators
- Bitwise Operators
- Comparison Operators
- Incrementing/Decrementing Operators
- Logical Operators
- String Operators
- Array Operators
- Type Operators
- Execution Operators
- Error Control Operators
আমরা অপারেন্ডের পক্ষে অপারেটরদের শ্রেণীবদ্ধ করতে পারি। এগুলিকে 3টি আকারে শ্রেণীবদ্ধ করা যেতে পারে:
- ইউনারি অপারেটর: একক অপারেন্ডে কাজ করে যেমন ++, — ইত্যাদি।
- বাইনারি অপারেটর: বাইনারি +, -, *, / ইত্যাদির মতো দুটি অপারেন্ডে কাজ করে।
- টারনারি অপারেটর: তিনটি অপারেন্ডে কাজ করে যেমন “?:”।
পাটিগণিত অপারেটর
পিএইচপি গাণিতিক অপারেটরগুলি সাংখ্যিক মানের সাথে যোগ, বিয়োগ ইত্যাদির মতো সাধারণ গাণিতিক ক্রিয়াকলাপ সম্পাদন করতে ব্যবহৃত হয়।
Operator | Name | Example | Explanation |
---|---|---|---|
+ | যোগ | $a + $b | অপারেন্ডের সমষ্টি |
– | বিয়োগ | $a – $b | অপারেন্ডের পার্থক্য |
* | গুণ | $a * $b | অপারেন্ডের পণ্য |
/ | বিভাগ | $a / $b | অপারেন্ডের ভাগফল |
% | মডুলাস | $a % $b | অপারেন্ডের অবশিষ্টাংশ |
** | ব্যাখ্যা | $a ** $b | $a শক্তি $b পর্যন্ত উত্থাপিত |
PHP 5.6-এ এক্সপোনেন্টিয়েশন (**) অপারেটর চালু করা হয়েছে.
অ্যাসাইনমেন্ট অপারেটর
অ্যাসাইনমেন্ট অপারেটরগুলি বিভিন্ন ভেরিয়েবলের মান নির্ধারণ করতে ব্যবহৃত হয়। বেসিক অ্যাসাইনমেন্ট অপারেটর হল “=”৷
Operator | Name | Example | Explanation | ||
---|---|---|---|---|---|
= | বরাদ্দ করুন | $a = $b | ডান অপারেন্ডের মান বাম অপারেন্ডে বরাদ্দ করা হয়। | ||
+= | যোগ করুন তারপর অ্যাসাইন করুন | $a += $b | $a = $a + $b এর মত যোগ | ||
-= | বিয়োগ তারপর Assign | $a -= $b | বিয়োগ একই $a = $a – $b | ||
*= | গুণ তারপর Assign | $a *= $b | $a = $a * $b এর মতো গুণ | ||
/= | ভাগ করুন তারপর অ্যাসাইন করুন | (ভাগফল) | $a /= $b | $a = $a / $b এর মত ভাগফল বের করুন | |
%= | ভাগ করুন তারপর অ্যাসাইন করুন | (অবশিষ্ট) | $a %= $b | $a = $a % $b এর মত অবশিষ্টাংশ খুঁজুন |
বিটওয়াইজ অপারেটর
বিটওয়াইজ অপারেটরগুলি অপারেন্ডগুলিতে বিট-স্তরের ক্রিয়াকলাপ সম্পাদন করতে ব্যবহৃত হয়। এই অপারেটরগুলি পূর্ণসংখ্যার মধ্যে নির্দিষ্ট বিটগুলির মূল্যায়ন এবং হেরফের করার অনুমতি দেয়।
Operator | Name | Example | Explanation |
---|---|---|---|
& | And | $a & $b | যে বিটগুলি $a এবং $b উভয় ক্ষেত্রেই 1 আছে তা 1 এ সেট করা হয়েছে, অন্যথায় 0। |
| | Or (Inclusive or) | $a | $b | যে বিটগুলি $a বা $b তে 1 আছে সেটি 1 এ সেট করা হয়েছে |
^ | Xor (Exclusive or) | $a ^ $b | যে বিটগুলি $a বা $b-এর মধ্যে 1 আছে সেটি 0-তে সেট করা হয়েছে। |
~ | Not | ~$a | যে বিটগুলি 1 সেট করে 0 এবং যে বিটগুলি 0 সেগুলি 1 সেট করা হয় |
<< | Shift left | $a << $b | অপারেন্ড $a $b ধাপের বিট বাম স্থানান্তর করুন |
>> | Shift right | $a >> $b | স্থানের $b সংখ্যা দ্বারা $a অপারেন্ডের বিটগুলিকে ডানদিকে স্থানান্তর করুন |
তুলনা অপারেটর
তুলনা অপারেটর দুটি মান তুলনা করার অনুমতি দেয়, যেমন সংখ্যা বা স্ট্রিং। তুলনামূলক অপারেটরদের তালিকা নীচে দেওয়া হল:
Operator | Name | Example | Explanation |
---|---|---|---|
== | Equal | $a == $b | $a $b এর সমান হলে TRUE ফেরত দিন |
=== | Identical | $a === $b | যদি $a $b এর সমান হয় এবং সেগুলি একই ডেটা টাইপের হয় তাহলে TRUE ফেরত দিন |
!== | Not identical | $a !== $b | যদি $a $b এর সমান না হয় এবং সেগুলি একই ডেটা টাইপের না হয় তাহলে TRUE ফেরত দিন |
!= | 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 | $a যদি $b এর থেকে কম বা সমান হয় তাহলে TRUE ফেরত দিন |
>= | Greater than or equal to | $a >= $b | Return TRUE if $a is greater than or equal $b |
<=> | Spaceship | $a <=>$b |
Return -1 if $a is less than $b |
Incrementing/Decrementing Operators
The increment and decrement operators are used to increase and decrease the value of a variable.
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
The logical operators are used to perform bit-level operations on operands. These operators allow the evaluation and manipulation of specific bits within the integer.
Operator | Name | Example | Explanation |
---|---|---|---|
and | And | $a and $b | Return TRUE if both $a and $b are true |
Or | Or | $a or $b | Return TRUE if either $a or $b is true |
xor | Xor | $a xor $b | Return TRUE if either $ or $b is true but not both |
! | Not | ! $a | Return TRUE if $a is not true |
&& | And | $a && $b | Return TRUE if either $a and $b are true |
|| | Or | $a || $b | Return TRUE if either $a or $b is true |
String Operators
The string operators are used to perform the operation on strings. There are two string operators in PHP, which are given below:
Operator | Name | Example | Explanation |
---|---|---|---|
. | Concatenation | $a . $b | Concatenate both $a and $b |
.= | Concatenation and Assignment | $a .= $b | First concatenate $a and $b, then assign the concatenated string to $a, e.g. $a = $a . $b |
Array Operators
The array operators are used in case of array. Basically, these operators are used to compare the values of arrays.
Operator | Name | Example | Explanation |
---|---|---|---|
+ | Union | $a + $y | Union of $a and $b |
== | Equality | $a == $b | Return TRUE if $a and $b have same key/value pair |
!= | Inequality | $a != $b | Return TRUE if $a is not equal to $b |
=== | Identity | $a === $b | Return TRUE if $a and $b have same key/value pair of same type in same order |
!== | Non-Identity | $a !== $b | Return TRUE if $a is not identical to $b |
<> | Inequality | $a <> $b | Return TRUE if $a is not equal to $b |
Type Operators
The type operator instanceof is used to determine whether an object, its parent and its derived class are the same type or not. Basically, this operator determines which certain class the object belongs to. It is used in object-oriented programming.
Output:
Charu is a developer. bool(true) bool(false)
Execution Operators
PHP has an execution operator backticks (“). PHP executes the content of backticks as a shell command. Execution operator and shell_exec() give the same result.
Operator | Name | Example | Explanation |
---|---|---|---|
“ | backticks | echo `dir`; | Execute the shell command and return the result. Here, it will show the directories available in current folder. |
Note: Note that backticks (“) are not single-quotes.
Error Control Operators
PHP has one error control operator, i.e., at (@) symbol. Whenever it is used with an expression, any error message will be ignored that might be generated by that expression.
Operator | Name | Example | Explanation |
---|---|---|---|
@ | at | @file (‘non_existent_file’) | Intentional file error |
PHP Operators Precedence
Let’s see the precedence of PHP operators with 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 |

