Chapterبەش 5 · Lectureوانە 5.8

Operatorsکارپێکەرەکان

Arithmetic, assignment, increment and decrement, comparison, logical, string and array operators, and the precedence rules that decide which one runs first. Every course example is run and corrected.

، ، و ، ، ، و و یاساکانی کە دیاری دەکەن کامیان یەکەم کار دەکات. هەموو نموونەیەکی کۆرسەکە تاقی کراوەتەوە و ڕاست کراوەتەوە.

25 min read24 خولەک خوێندنەوە · 24 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Name the parts of an expression: operators and operands.
  • Calculate with + - * / % ** and predict when the result is a float.
  • Use = and the compound assignment operators such as += and .=.
  • Explain the difference between ++$x and $x++.
  • Compare values with ==, ===, !=, !==, <>, <, >, <=, >= and <=>, and know when to prefer ===.
  • Combine conditions with &&, ||, ! and xor, and avoid the and/or precedence trap.
  • Use operator precedence and parentheses to predict the value of an expression.
  • بەشەکانی بناسیت: و .
  • بە + - * / % ** هەژمار بکەیت و پێشبینی بکەیت کەی ئەنجامەکە .
  • = و هاوشێوە لێکدراوەکانی، وەک += و .=، بەکاربهێنیت.
  • جیاوازیی نێوان ++$x و $x++ ڕوون بکەیتەوە.
  • بە ==، ===، !=، !==، <>، <، >، <=، >= و <=> بەراورد بکەیت و بزانیت کەی === باشترە.
  • بە &&، ||، ! و xor پێکەوە ببەستیت و خۆت لە تەڵەی پێشینەیی and/or بپارێزیت.
  • بە و کەوانە پێشبینی بکەیت.

What operators doکارپێکەرەکان چی دەکەن

Programs calculate all the time: a shop adds prices, a school averages marks, a login page compares a typed password. In PHP you do this work with . An operator is a symbol, such as +, = or ==, that does something with one or more values. The values it works on are called . Operators and operands together form an , and every expression produces a value.

هەمیشە هەژمار دەکەن: دوکانێک کۆی پارەی کڕینەکان دەردەهێنێت، قوتابخانەیەک تێکڕای نمرەکان دەردەهێنێت، لاپەڕەی نووسراو بەراورد دەکات. لە PHPـدا ئەم کارانە بە دەکەیت. هێمایەکە، وەک +، = یان ==، کە کارێک لەسەر یەک یان چەند دەکات. ئەو کاریان لەسەر دەکرێت پێیان دەوترێت . و پێکەوە پێک دەهێنن و هەموو بەرهەم دەهێنێت.

One statement, two operatorsیەک ڕستە، دوو کارپێکەرPHP
$total = $price * 3;
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

* multiplies its two operands, $price and 3. Then = stores the result in $total.

* دوو ($price و 3) لێک دەدات. پاشان = ئەنجامەکە لە $totalـدا هەڵدەگرێت.

Definitionپێناسە

A symbol that does something with one or more values, such as + (add), == (compare) or . (join strings). The values it works on are its .

هێمایەکە کە کارێک لەسەر یەک یان چەند نرخێک ئەنجام دەدات، وەک + (کۆکردنەوە)، == (بەراوردکردن) یان . (لکاندنی دەق). ئەو نرخانەی کاریان لەسەر دەکات پێیان دەگوترێت .

Definitionپێناسە

A value that an works on. In 5 * 2, the operands are 5 and 2.

ئەو نرخەیە کە کاری لەسەر دەکات. لە 5 * 2 دا، 5 و 2 کارپێکراون.

Definitionپێناسە

Any piece of code that produces a value, such as 5 + 3, $price * 2 or $age >= 18. Expressions are parts of .

هەر پارچە کۆدێکە کە بەرهەم دەهێنێت، وەک 5 + 3 یان $price * 2 یان $age >= 18. دەربڕینەکان بەشێکن لە .

Operators are like calculator keysکارپێکەرەکان وەک دوگمەکانی ئامێری حیساب

Think of the calculator on a shopkeeper's counter in the bazaar. The numbers you type are the operands, and the keys +, -, × and ÷ are the operators. PHP has the same kind of keys, plus keys that store results, compare two things and make yes/no decisions.

بیر لە ئامێری حیسابی سەر مێزی دوکاندارێک لە بازاڕدا بکەرەوە. ئەو ژمارانەی دەیاننووسیت و دوگمەکانی +، -، × و ÷ . PHP هەمان جۆرە دوگمەی هەیە، لەگەڵ دوگمەی تر بۆ هەڵگرتنی ئەنجام، بەراوردکردنی دوو شت و بڕیاردانی بەڵێ/نەخێر.

Where the analogy stops workingسنووری ئەم نموونەیە

A calculator works left to right as you press the keys. PHP reads the whole expression first and follows fixed rules about which operator goes first.

ئامێری حیساب بە پێی ڕیزبەندیی پەنجەنانت لە چەپەوە بۆ ڕاست کار دەکات. PHP سەرەتا هەموو دەخوێنێتەوە و یاسای جێگیر پەیڕەو دەکات کە کام یەکەم کار دەکات.

The operator families in this lectureخێزانەکانی لەم وانەیەدا
FamilyخێزانOperatorsSectionبەش
Arithmeticژمێرەیی+ - * / % **Arithmeticژمێرەیی
Assignment= += -= *= /= %= .=Assignmentبەشی دانانی نرخ
Increment / decrementزیاد و کەمکردن بە یەک++ --Increment and decrementزیادکردن و کەمکردنەوە
Comparisonبەراوردکردن== === != <> !== < > <= >= <=>Comparisonبەراوردکردن
Logicalلۆجیکی&& || ! and or xorLogicalلۆجیکی
String. .=String and array operatorsکارپێکەرەکانی زنجیرەنووسە و ڕیزەک
Array+ == === != <> !==String and array operatorsکارپێکەرەکانی زنجیرەنووسە و ڕیزەک

Arithmetic operatorsکارپێکەرە ژمێرەییەکان

PHP's do school mathematics with numbers. The table uses $x = 10 and $y = 4.

بیرکاریی قوتابخانە لەسەر ژمارەکان دەکەن. ئەم خشتەیە $x = 10 و $y = 4 بەکاردەهێنێت.

Arithmetic operators with $x = 10 and $y = 4 (checked with PHP 8.5) بە $x = 10 و $y = 4 (بە ⁦PHP 8.5⁩ پشکنراون)
OperatorNameناوExampleنموونەResultئەنجام
+Additionکۆکردنەوە$x + $y14
-Subtractionلێدەرکردن$x - $y6
*Multiplicationلێکدان$x * $y40
/Divisionدابەشکردن$x / $y2.5
%Modulus (remainder) (ئەوەی دوای دابەشکردن دەمێنێتەوە)$x % $y2
**Exponent (power)توان$x ** $y10000
-Negation (one operand)نەرێکردن (یەک )-$x-10
  • / gives a whole number when the division is exact (10 / 5 is 2) and a decimal number () when it is not (10 / 4 is 2.5).
  • % gives the remainder: 10 divided by 4 is 2, remainder 2. It is perfect for checking even and odd numbers: $n % 2 is 0 for even numbers.
  • ** raises to a power: 2 ** 3 is 2 × 2 × 2 = 8.
  • Lab 2 writes echo($x + $y);. The parentheses only group the expression; echo is not a function, so echo $x + $y; works the same.
  • / کاتێک دابەشکردنەکە تەواو بێت دەدات (10 / 5 دەکاتە 2) و کاتێک تەواو نەبێت ژمارەیەکی دەیدەیی () دەدات (10 / 4 دەکاتە 2.5).
  • % باقیی دابەشکردن دەدات: ⁦10⁩ دابەش 4 دەکاتە 2 و 2 دەمێنێتەوە. بۆ زانینی ژمارەی جووت و تاک زۆر گونجاوە: $n % 2 بۆ ژمارەی جووت 0ـە.
  • ** توان دەکات: 2 ** 3 دەکاتە ⁦2 × 2 × 2 = 8⁩.
  • تاقیگەی 2 دەنووسێت echo($x + $y);. کەوانەکان تەنها کۆ دەکەنەوە؛ echo نییە، بۆیە echo $x + $y;ـیش هەمان کار دەکات.
Definitionپێناسە

The remainder left after dividing one whole number by another, given by the % operator. 10 % 3 is 1, and $n % 2 == 0 tests whether a number is even.

ئەو پاشماوەیەیە کە دوای دابەشکردنی بەسەر ژمارەیەکی تردا دەمێنێتەوە و کارپێکەری % دەیدات. 10 % 3 دەکاتە 1 و $n % 2 == 0 دەپشکنێت ئایا ژمارەکە جووتە.

arith.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo 2 ** 3;          // exponent: 2 × 2 × 2
echo "<br>";
echo 10 / 5;          // exact division gives an integer
echo "<br>";
echo intdiv(10, 4);   // whole-number division
echo "<br>";
echo -7 % 3;          // the sign comes from the left number
echo "<br>";
echo 7 % -3;
echo "<br>";
$x = 5;
echo -$x;             // negation
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

Exponent: 2 to the power 3.

توان: 2 بە توانی 3.

Lineدێڕی 4

An exact division gives an integer.

دابەشکردنی تەواو دەدات.

Lineدێڕی 6

intdiv() divides and drops the decimal part.

intdiv() دابەش دەکات و بەشی دەیدەیی فڕێ دەدات.

Lineدێڕی 8-10

With %, the sign of the result follows the left number.

لە %ـدا، نیشانەی سالب یان موجەبی ئەنجامەکە بە پێی ژمارەی لای چەپە.

Lineدێڕی 13

A minus sign before one value changes its sign.

نیشانەی کەم لە پێش یەک نیشانەکەی دەگۆڕێت.

Quick checkپشکنینی خێراWhat does echo 10 % 3; print?echo 10 % 3; چی چاپ دەکات؟

PHP Full Course for free 🐘Bro Code · Englishئینگلیزی · 3M viewsبینین · 65K likesلایک · Partبەشی 28:02–34:38 (ofلە 4:00:00)

How to create a function, send values in with arguments, and get a result back with return, with a short practice example.

چۆن دروست بکەیت، بە بنێریتە ناوی و بە return ئەنجامێک لێی وەربگریتەوە، لەگەڵ ڕاهێنانێکی کورت.

Plays only the 'arithmetic' chapter: operators, ++/--, precedence (28:02–34:38).

تەنها بەشی arithmetic پەخش دەبێت (⁦28:02⁩ تا ⁦34:38⁩): ، ++/-- و .

Arithmetic operatorsکارپێکەرە ژمێرەییەکان

The lecture's "Basic Math" exampleنموونەی "⁦Basic Math⁩"ی وانەکە

The lecture mixes HTML text and PHP. It calculates ((1 + 2 + $var1) * $var2) / 2 - 5 with $var1 = 3 and $var2 = 4:

وانەکە دەقی HTML و PHP تێکەڵ دەکات. ((1 + 2 + $var1) * $var2) / 2 - 5 هەژمار دەکات بە $var1 = 3 و $var2 = 4:

math.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$var1 = 3;
$var2 = 4;
?>
Basic Math:
<?php echo ((1 + 2 + $var1) * $var2) / 2 - 5; ?>
<br />
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-3

Two variables, set in the first PHP block.

دوو ، لە یەکەم بلۆکی PHPـدا دانراون.

Lineدێڕی 6

Brackets first, then * and /, then -. The result is 7.

سەرەتا کەوانەکان، پاشان * و /، پاشان -. ئەنجامەکە 7ـە.

Six boxes from top to bottom show how PHP works out ((1 + 2 + $var1) * $var2) / 2 - 5 with $var1 = 3 and $var2 = 4: put in the values, add inside the inner brackets to get 6, multiply by 4 to get 24, divide by 2 to get 12, and subtract 5 to get 7.شەش چوارگۆشە لە سەرەوە بۆ خوارەوە پیشان دەدەن PHP چۆن ((1 + 2 + $var1) * $var2) / 2 - 5 هەژمار دەکات کاتێک $var1 = 3 و $var2 = 4: ژمارەکان دادەنرێن، ناو کەوانەی ناوەوە کۆ دەکرێتەوە و دەبێت بە 6، لێکدان لە 4 دەبێت بە 24، دابەش بە 2 دەبێت بە 12 و لێدەرکردنی 5 دەبێت بە 7.
Step by step: brackets first, then multiplication and division, then subtraction.هەنگاو بە هەنگاو: سەرەتا کەوانەکان، پاشان لێکدان و دابەشکردن، پاشان لێدەرکردن.CêIT

Arithmetic operatorsکارپێکەرە ژمێرەییەکان

Two things that stop a scriptدوو شت کە دەسنووسێک دەوەستێنن

Dividing by zero is not allowed. PHP 8 throws a DivisionByZeroError for both / and %:

دابەشکردن بە سفر ڕێگەپێدراو نییە. ⁦PHP 8⁩ بۆ هەردوو / و % DivisionByZeroError دەدات:

divide.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$apples = 10;
$children = 0;
echo $apples / $children;
?>

Arithmetic on strings works only when the string looks like a number. PHP converts "5" to 5 (). Text such as "abc" cannot be converted, and PHP 8 throws a TypeError:

هەژمارکردن لەسەر تەنها کاتێک کار دەکات کە لە ژمارە بچێت. PHP "5" دەکات بە 5 (). دەقێکی وەک "abc" ناگۆڕدرێت و ⁦PHP 8⁩ TypeError دەدات:

numbers.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "5" + "5";
echo "<br>";
echo "10" * "2";
echo "<br>";
echo "7" % "4";
echo "<br>";
echo "abc" + 1;
?>
Quick checkپشکنینی خێراWhat happens when PHP runs echo 10 % 0;?کاتێک PHP echo 10 % 0; جێبەجێ دەکات چی ڕوودەدات؟

Assignment operatorsکارپێکەرەکانی دانانی نرخ

= is the basic . It does not mean "is equal to". It means: work out the value on the right, then store it in the variable on the left. So $x = $x + 1; is not a broken equation; it means "take $x, add 1, and put the result back into $x".

= بنەڕەتیترین . واتای "یەکسانە بە" نییە. واتاکەی ئەمەیە: لای ڕاست هەژمار بکە، پاشان لە لای چەپدا هەڵیبگرە. کەواتە $x = $x + 1; هاوکێشەیەکی نادروست نییە؛ واتە "$x وەربگرە، یەکی بخە سەر و ئەنجامەکە بگەڕێنەوە ناو $x".

Definitionپێناسە

Storing a value in a variable with the =. The right side is worked out first, then the result is put into the variable on the left.

خەزنکردنی لە بە (=). سەرەتا لای ڕاست هەژمار دەکرێت، پاشان ئەنجامەکەی دەخرێتە ناو ئەو گۆڕاوەی لای چەپە.

A compound assignment operator does a calculation and the assignment in one step. The lecture shows +=: "you can add any value and change the value of the variable".

جۆرێکی لێکدراوی هەژمارکردن و بە یەک هەنگاو دەکات. وانەکە += پیشان دەدات: "دەتوانیت هەر زیاد بکەیت و بگۆڕیت".

plus-equals.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$var1 = 3;
$var2 = 4;
?>
+=: <?php
$var2 += 4;
echo $var2;
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-3

$var2 starts at 4.

$var2 بە 4 دەست پێ دەکات.

Lineدێڕی 6

$var2 += 4; is short for $var2 = $var2 + 4;, so $var2 becomes 8.

$var2 += 4; کورتکراوەی $var2 = $var2 + 4;ـە، بۆیە $var2 دەبێت بە 8.

Assignment operators
OperatorExampleنموونەSame asهەمان
=$x = 5;store 5 in $x5 لە $xـدا هەڵبگرە
+=$x += 30;$x = $x + 30;
-=$x -= 20;$x = $x - 20;
*=$x *= 25;$x = $x * 25;
/=$x /= 10;$x = $x / 10;
%=$x %= 15;$x = $x % 15;
**=$x **= 3;$x = $x ** 3;
.=$s .= "!";$s = $s . "!";
assign.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "<pre>";
$x = 10;
$x /= 4;
var_dump($x);

$p = 2;
$p **= 3;
var_dump($p);

$greeting = "Hello";
$greeting .= ", Hana";
var_dump($greeting);
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3-4

/= can turn an integer into a float: 10 / 4 = 2.5.

/= دەتوانێت بکات بە : ⁦10 / 4 = 2.5⁩.

Lineدێڕی 7-8

**=: 2 to the power 3 = 8.

**=: 2 بە توانی ⁦3 = 8⁩.

Lineدێڕی 11-12

.= adds text to the end of a string.

.= دەق دەخاتە کۆتایی .

Quick checkپشکنینی خێراWhat does $x = 10; $x -= 3; $x *= 2; echo $x; print?$x = 10; $x -= 3; $x *= 2; echo $x; چی چاپ دەکات؟

Assignment operatorsکارپێکەرەکانی دانانی نرخ

An assignment is also a valueدانانی نرخ خۆی نرخێکیشە

An assignment is an expression too: its value is the value that was stored. That is why echo $a = 5; prints 5, why $b = $c = 0; sets both variables, and why the course notes' row $var = 4; print($var = 5); prints 5.

خۆی : هەمان ئەو کە هەڵگیرا. لەبەر ئەوەیە echo $a = 5; ژمارە 5 چاپ دەکات، $b = $c = 0; هەردوو دادەنێت و ڕیزەکەی تێبینییەکانی کۆرسەکە $var = 4; print($var = 5); ژمارە 5 چاپ دەکات.

assign-value.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo $a = 5;
echo "<br>";
$b = $c = 0;
echo $b . $c;
echo "<br>";
$var = 4;
print($var = 5);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

The assignment stores 5 and also gives 5 to echo.

5 هەڵدەگرێت و هەروەها 5 دەدات بە echo.

Lineدێڕی 4

Right to left: first $c = 0, then $b gets that value.

لە ڕاستەوە بۆ چەپ: سەرەتا $c = 0، پاشان $b هەمان وەردەگرێت.

Lineدێڕی 7-8

From the course notes: prints 5.

لە تێبینییەکانی کۆرسەکەوە: 5 چاپ دەکات.

Increment and decrementزیادکردن و کەمکردنەوە

Adding 1 to a variable is so common that PHP has a special operator for it: ++ (increment). -- (decrement) takes 1 away. $x++; does the same as $x += 1; and $x = $x + 1;. You will use this a lot in loops to count.

1 بۆ ئەوەندە باوە کە PHP تایبەتی بۆ هەیە: ++ (). -- () یەک کەم دەکاتەوە. $x++; هەمان کاری $x += 1; و $x = $x + 1; دەکات. ئەمە زۆر لە خولەکان بۆ ژماردن بەکاردەهێنیت.

Definitionپێناسە

Adding 1 to a variable with the ++ operator. $i++ does the same as $i = $i + 1 and is used a lot in loops.

زیادکردنی 1 بۆ سەر گۆڕاوێک بە کارپێکەری ++. $i++ وەک $i = $i + 1 وایە و زۆر لەناو بەکار دێت.

Definitionپێناسە

Subtracting 1 from a variable with the -- operator. $i-- does the same as $i = $i - 1.

کەمکردنەوەی 1 لە گۆڕاوێک بە کارپێکەری --. $i-- وەک $i = $i - 1 وایە.

incdec.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php $var2 = 5; ?>
Increment: <?php $var2++; echo $var2; ?>
<br>
Decrement: <?php $var2--; echo $var2; ?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

$var2 starts at 5. This must be inside <?php ... ?>.

$var2 بە 5 دەست پێ دەکات. دەبێت لەناو <?php ... ?>ـدا بێت.

Lineدێڕی 2

Increment by 1: 5 becomes 6.

زیاد کردن بە ⁦1: 5⁩ دەبێت بە 6.

Lineدێڕی 4

Decrement by 1: 6 becomes 5 again.

کەم کردنەوە بە ⁦1: 6⁩ دیسان دەبێتەوە بە 5.

Increment and decrementزیادکردن و کەمکردنەوە

Prefix or postfix: before or after?پێشگر و پاشگر: پێش یان دوا؟

You can write the operator before the variable (prefix: ++$x) or after it (postfix: $x++). On its own line there is no difference. The difference appears when the value is used at the same moment, for example inside echo:

دەتوانیت پێش بنووسیت (پێشگر: ++$x) یان دوای (پاشگر: $x++). ئەگەر لەسەر دێڕی خۆی بێت هیچ جیاوازییەک نییە. جیاوازییەکە کاتێک دەردەکەوێت کە لە هەمان ساتدا بەکاربهێنرێت، بۆ نموونە لەناو echoـدا:

The four formsچوار شێوەکە
CodeکۆدNameناوWhat happensچی ڕوودەدات
++$xPre-incrementپێش-Adds 1 first, then gives the new valueسەرەتا 1 زیاد دەکات، پاشان دەدات
$x++Post-incrementپاش-Gives the old value first, then adds 1سەرەتا دەدات، پاشان 1 زیاد دەکات
--$xPre-decrementپێش-Takes 1 away first, then gives the new valueسەرەتا 1 کەم دەکاتەوە، پاشان دەدات
$x--Post-decrementپاش-Gives the old value first, then takes 1 awayسەرەتا دەدات، پاشان 1 کەم دەکاتەوە
Definitionپێناسە

The two positions of ++ or --. Prefix (++$i) changes the variable first and then gives the new value; postfix ($i++) gives the old value first and then changes the variable.

دوو شوێنی ++ یان --ـن. لە شێوەی پێشگردا (++$i) سەرەتا دەگۆڕێت و پاشان نرخە نوێیەکە دەدات؛ لە شێوەی پاشگردا ($i++) سەرەتا نرخە کۆنەکە دەدات و پاشان دەگۆڕێت.

Two panels. Left: echo ++$x with $x = 10. Step 1 adds 1 so $x becomes 11, step 2 gives the new value, so 11 is printed. Right: echo $x++ with $x = 10. Step 1 gives the old value, so 10 is printed, step 2 adds 1 so $x becomes 11. In both cases $x is 11 afterwards.دوو بەش. چەپ: echo ++$x کاتێک $x = 10. هەنگاوی یەکەم یەک زیاد دەکات و $x دەبێت بە 11، هەنگاوی دووەم نرخە نوێیەکە دەدات، بۆیە 11 چاپ دەبێت. ڕاست: echo $x++ کاتێک $x = 10. هەنگاوی یەکەم نرخە کۆنەکە دەدات، بۆیە 10 چاپ دەبێت، هەنگاوی دووەم یەک زیاد دەکات و $x دەبێت بە 11. لە هەردوو حاڵەتدا دواتر $x دەکاتە 11.
Prefix changes the variable first; postfix uses the old value first. Afterwards the variable is the same.پێشگر سەرەتا دەگۆڕێت؛ پاشگر سەرەتا بەکاردەهێنێت. دواتر لە هەردووکیاندا وەک یەکە.CêIT
Quick checkپشکنینی خێرا$x = 5; echo $x++; echo $x; prints…$x = 5; echo $x++; echo $x; چی چاپ دەکات؟

Increment and decrementزیادکردن و کەمکردنەوە

The four forms in the course notesچوار شێوەکە لە تێبینییەکانی کۆرسەکەدا

The course notes show all four forms, each starting from $a = 8. We added <br> so that each pair of numbers (the value echo printed, then the variable afterwards) is on its own line:

تێبینییەکانی کۆرسەکە هەر چوار شێوەکە پیشان دەدەن، هەر یەکەیان بە $a = 8 دەست پێ دەکات. <br>مان زیاد کرد بۆ ئەوەی هەر جووتە ژمارەیەک ( echo چاپی کرد، پاشان دوای ئەوە) لەسەر دێڕی خۆی بێت:

pre-post.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$a = 8;
echo $a++;   // Output: 8
echo $a;     // Output: 9
echo "<br>";

$a = 8;
echo ++$a;   // Output: 9
echo $a;     // Output: 9
echo "<br>";

$a = 8;
echo $a--;   // Output: 8
echo $a;     // Output: 7
echo "<br>";

$a = 8;
echo --$a;   // Output: 7
echo $a;     // Output: 7
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-4

Post-increment: prints the old value 8, then $a is 9.

پاش-: 8 چاپ دەکات، پاشان $a دەبێت بە 9.

Lineدێڕی 7-9

Pre-increment: $a becomes 9 first, so both prints show 9.

پێش-: سەرەتا $a دەبێت بە 9، بۆیە هەردوو چاپکردن 9 پیشان دەدەن.

Lineدێڕی 12-14

Post-decrement: prints 8, then $a is 7.

پاش-: 8 چاپ دەکات، پاشان $a دەبێت بە 7.

Lineدێڕی 17-19

Pre-decrement: $a becomes 7 first.

پێش-: سەرەتا $a دەبێت بە 7.

Quick checkپشکنینی خێراWhat does $a = 3; echo $a--; echo $a; print?$a = 3; echo $a--; echo $a; چی چاپ دەکات؟

Comparison operatorsکارپێکەرەکانی بەراوردکردن

A compares two values and answers with a : true or false. These answers are what if statements and loops use to make decisions (see Conditional statements).

دوو بەراورد دەکات و وەڵامەکەی : true یان false. و ئەم وەڵامانە بۆ بڕیاردان بەکاردەهێنن (بڕوانە ڕستە مەرجییەکان).

Definitionپێناسە

An operator that compares two values and gives true or false: ==, !=, <, >, <= and >=. PHP also has === and !==, which check that the types are the same too.

کە دوو نرخ بەراورد دەکات و ڕاست یان هەڵە دەدات: ==، !=، <، >، <= و >=. PHP هەروەها === و !==ـی هەیە کە دەپشکنن جۆرەکانیش وەک یەک بن.

The lecture and the course summary list six of them under the heading "Boolean Operators": >, >=, <, <=, == and !=. Here is the complete list:

وانەکە و پوختەی کۆرسەکە شەشیان لە ژێر ناونیشانی "⁦Boolean Operators⁩"ـدا ڕیز دەکەن: >، >=، <، <=، == و !=. ئەمەش لیستە تەواوەکەیە:

All comparison operatorsهەموو
OperatorNameناوtrue when…کەی trueـە…In the course list?لە لیستەکەی کۆرسدا؟
$a == $bEqualیەکسانthe values are equal (after PHP converts types if needed) یەکسانن (ئەگەر پێویست بێت، PHP سەرەتا جۆرەکان دەگۆڕێت)Yesبەڵێ
$a === $bIdenticalوەک یەکthe values are equal and the types are the same یەکسانن و جۆرەکانیشیان وەک یەکنNo (added)نەخێر (زیاد کراوە)
$a != $bNot equalیەکسان نییەthe values are not equal یەکسان نینYesبەڵێ
$a <> $bNot equal (another spelling)یەکسان نییە (نووسینێکی تر)same as !=وەک !=No (added)نەخێر (زیاد کراوە)
$a !== $bNot identicalوەک یەک نییەthe values or the types are different یان جۆرەکان جیاوازنNo (added)نەخێر (زیاد کراوە)
$a < $bLess thanبچووکترە لە$a is smaller$a بچووکترەYesبەڵێ
$a > $bGreater thanگەورەترە لە$a is bigger$a گەورەترەYesبەڵێ
$a <= $bLess than or equal toبچووکترە یان یەکسانە$a is smaller or equal$a بچووکترە یان یەکسانەYesبەڵێ
$a >= $bGreater than or equal toگەورەترە یان یەکسانە$a is bigger or equal$a گەورەترە یان یەکسانەYesبەڵێ
$a <=> $bSpaceshipکەشتیی ئاسمانی ⁦(spaceship)⁩not true/false: gives -1, 0 or 1true/false نادات: -1، 0 یان 1 دەداتNo (added)نەخێر (زیاد کراوە)
compare.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$a = 5;
$b = "5";
echo "<pre>";
var_dump($a == $b);
var_dump($a === $b);
var_dump($a != $b);
var_dump($a <> $b);
var_dump($a !== $b);
var_dump($a > 3);
var_dump($a >= 5);
var_dump($a < 5);
var_dump($a <= 4);
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-3

An integer 5 and a string "5".

5 و "5".

Lineدێڕی 5

==: PHP turns "5" into 5, so they are equal.

==: PHP "5" دەکات بە 5، بۆیە یەکسانن.

Lineدێڕی 6

===: an int and a string are different types, so false.

===: int و string دوو جۆری جیاوازن، بۆیە false.

Lineدێڕی 7-8

!= and <> are the same operator.

!= و <> هەمان .

Lineدێڕی 9

!==: different types, so true.

!==: جۆری جیاواز، بۆیە true.

PHP Operators Part 1 - Full PHP 8 TutorialProgram With Gio · Englishئینگلیزی · 73K viewsبینین · 2.2K likesلایک · Partبەشی 7:39–14:26 (ofلە 14:26)

The comparison part explains == and ===, != and !==, and greater-than and less-than, with clear PHP 8 examples.

بەشی == و ===، != و !== و گەورەتر (>) و بچووکتر (<) ڕوون دەکاتەوە، بە نموونەی ڕوونی 8.

Watch from 7:39 to the end: the comparison operators chapter.

لە ⁦7:39⁩ تا کۆتایی سەیر بکە: بەشی .

Comparison operatorsکارپێکەرەکانی بەراوردکردن

== or ===?== یان ===؟

Same amount, or same thing?هەمان بڕ، یان هەمان شت؟

Imagine a 5,000-dinar note and a piece of paper with "5000" written on it. If you only ask "is the amount the same?" the answer is yes: that is ==. If you ask "is it the same amount and the same kind of thing?" the answer is no: that is ===.

وای دابنێ پارەیەکی ⁦5,000⁩ دیناری و پارچە کاغەزێکت هەیە کە "⁦5000⁩"ی لەسەر نووسراوە. ئەگەر تەنها بپرسیت "بڕەکەیان وەک یەکە؟" وەڵامەکە بەڵێیە: ئەمە ==ـە. ئەگەر بپرسیت "هەم بڕەکە و هەم جۆری شتەکە وەک یەکن؟" وەڵامەکە نەخێرە: ئەمە ===ـە.

Where the analogy stops workingسنووری ئەم نموونەیە

PHP's rules for converting types with == are more complicated than this, and sometimes surprising (see below).

یاساکانی PHP بۆ لە ==ـدا لەمە ئاڵۆزترن و هەندێک جار سەرسوڕهێنەرن (لە خوارەوە ببینە).

== converts types before comparing (). PHP 8 made these rules safer: a number and a non-numeric string are now compared as strings. Some results still surprise beginners:

== پێش بەراوردکردن جۆرەکان دەگۆڕێت (). ⁦PHP 8⁩ ئەم یاسایانەی سەلامەتتر کرد: ئێستا ژمارەیەک و کە ژمارە نەبێت وەک بەراورد دەکرێن. هێشتا هەندێک ئەنجام سەری فێرخوازان سوڕ دەهێنن:

loose.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "<pre>";
var_dump(0 == "abc");
var_dump("1" == "01");
var_dump("10" == "1e1");
var_dump(null == false);
var_dump("abc" == "ABC");
var_dump(1.5 == "1.5");
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

false in PHP 8. (PHP 7 said true here, a famous trap.)

لە ⁦PHP 8⁩دا false. (⁦PHP 7⁩ لێرەدا دەیگوت true، تەڵەیەکی بەناوبانگ.)

Lineدێڕی 4-5

Two numeric strings are compared as numbers: "01" is 1 and "1e1" is 10.

دوو ژمارەیی وەک ژمارە بەراورد دەکرێن: "01" دەکاتە 1 و "1e1" دەکاتە ⁦10⁩.

Lineدێڕی 6

null and false are both "empty", so they are equal.

null و false هەردووکیان "بەتاڵ"ن، بۆیە یەکسانن.

Lineدێڕی 7

String comparison is .

بەراوردکردنی .

Quick checkپشکنینی خێراWhich expression is false?کام falseـە؟

Comparison operatorsکارپێکەرەکانی بەراوردکردن

Comparing stringsبەراوردکردنی زنجیرەنووسەکان

Strings are compared character by character, like words in a dictionary. Capital and small letters are different characters. When both strings look like numbers, PHP compares them as numbers.

پیت بە پیت بەراورد دەکرێن، وەک وشەکان لە فەرهەنگدا. پیتی گەورە و بچووک دوو جیاوازن. کاتێک هەردوو لە ژمارە دەچن، PHP وەک ژمارە بەراوردیان دەکات.

compare-text.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "<pre>";
var_dump("No" == "no");
var_dump("apple" < "banana");
var_dump("10" == "10.0");
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

"No" and "no" are different, because capital and small letters are different characters.

"No" و "no" جیاوازن، چونکە پیتی گەورە و بچووک دوو جیاوازن.

Lineدێڕی 4

Strings are compared letter by letter, like in a dictionary: "apple" comes before "banana".

پیت بە پیت بەراورد دەکرێن، وەک لە فەرهەنگدا: "apple" پێش "banana" دێت.

Lineدێڕی 5

Two numeric strings are compared as numbers: 10 equals 10.0.

دوو ژمارەیی وەک ژمارە بەراورد دەکرێن: ⁦10⁩ یەکسانە بە ⁦10.0⁩.

Comparison operatorsکارپێکەرەکانی بەراوردکردن

The spaceship operator <=>کارپێکەری spaceship <=>

$a <=> $b gives -1 if $a is smaller, 0 if they are equal and 1 if $a is bigger. It is used mostly for sorting.

$a <=> $b ئەگەر $a بچووکتر بێت -1 دەدات، ئەگەر یەکسان بن 0 و ئەگەر $a گەورەتر بێت 1. زیاتر بۆ ڕیزکردن بەکاردێت.

spaceship.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo 1 <=> 2;
echo "<br>";
echo 2 <=> 2;
echo "<br>";
echo 3 <=> 2;
echo "<br>";
echo "apple" <=> "banana";
?>
Quick checkپشکنینی خێراWhat does echo 5 <=> 9; print?echo 5 <=> 9; چی چاپ دەکات؟

Logical operatorsکارپێکەرە لۆجیکییەکان

PHP's combine true/false values. You use them to join several into one, for example "the user is an adult and has a ticket".

true/false پێکەوە دەبەستن. بۆ پێکەوەبەستنی چەند لە یەکێکدا بەکاریان دەهێنیت، بۆ نموونە " گەورەیە و بلیتی هەیە".

Definitionپێناسە

An operator that combines true/false values: and, or and not. Python writes them as words (and, or, not); PHP, Java and C# use &&, || and ! (PHP also has and, or and xor with lower precedence).

کە نرخەکانی ڕاست و هەڵە پێکەوە دەبەستێت: and، or و ⁦not. Python⁩ بە وشە دەیاننووسێت (and، or، not)؛ PHP، Java و ⁦C#⁩ &&، || و ! بەکار دەهێنن (PHP هەروەها and، or و xorـی هەیە بە پێشینەیی نزمتر).

Logical operators
OperatorNameناوtrue when…کەی trueـە…
$a && $bAndوboth are trueهەردووکیان ڕاستن
$a and $bAnd (low precedence)و (پێشینەیی نزم)both are trueهەردووکیان ڕاستن
$a || $bOrیانat least one is trueلانیکەم یەکێکیان ڕاستە
$a or $bOr (low precedence)یان (پێشینەیی نزم)at least one is trueلانیکەم یەکێکیان ڕاستە
$a xor $bExclusive orیان-ی تایبەت ⁦(xor)⁩exactly one is true, not bothتەنها یەکێکیان ڕاستە، نەک هەردووکیان
!$aNotنا$a is false$a ناڕاستە
Truth table: every combination of two values: هەموو تێکەڵەیەکی دوو
$a$b$a && $b$a || $b$a xor $b!$a
truetruetruetruefalsefalse
truefalsefalsetruetruefalse
falsetruefalsetruetruetrue
falsefalsefalsefalsefalsetrue

AND, OR and NOT are also the of digital circuits, and they follow the same laws. Logic Design teaches those laws in Boolean Expressions and Laws.

AND، OR و NOT هەروەها بازنە دیجیتاڵەکانیشن و هەمان یاساکان پەیڕەو دەکەن. دیزاینی ئەو یاسایانە لە دەربڕینە بوولییەکان و یاساکانی جەبری بوول فێر دەکات.

logical.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$age = 20;
$hasTicket = true;
echo "<pre>";
var_dump($age >= 18 && $hasTicket);
var_dump($age < 18 || $hasTicket);
var_dump(!$hasTicket);
var_dump($age >= 18 and $hasTicket);
var_dump(true xor true);
var_dump(true xor false);
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 5

Both parts are true, so && gives true.

هەردوو بەش ڕاستن، بۆیە && ئەنجامی true دەدات.

Lineدێڕی 6

The first part is false, but || needs only one true part.

بەشی یەکەم ناڕاستە، بەڵام || تەنها یەک بەشی ڕاستی پێویستە.

Lineدێڕی 7

! turns true into false.

! true دەکات بە false.

Lineدێڕی 9-10

xor is true only when exactly one side is true.

xor تەنها کاتێک ڕاستە کە ڕێک یەک لایەن ڕاست بێت.

Quick checkپشکنینی خێراWhat does var_dump(true xor true); show?var_dump(true xor true); چی پیشان دەدات؟

PHP Operators Part 2 - Full PHP 8 TutorialProgram With Gio · Englishئینگلیزی · 61K viewsبینین · 2.1K likesلایک · Partبەشی 3:17–7:55 (ofلە 16:13)

Explains &&, || and !, the word forms and, or and xor, and how PHP stops checking early (short-circuit).

&&، || و ! ڕوون دەکاتەوە، هەروەها شێوە وشەییەکانی and، or و xor و چۆن زوو لە پشکنین دەوەستێت ().

Watch 3:17–7:55: logical operators and short-circuiting only.

لە ⁦3:17⁩ تا ⁦7:55⁩ سەیر بکە: تەنها و .

Logical operatorsکارپێکەرە لۆجیکییەکان

PHP stops as soon as it knows the answerPHP هەر کە وەڵامەکەی زانی دەوەستێت

With &&, if the left side is false the whole answer must be false, so PHP does not even look at the right side. With ||, if the left side is true PHP skips the right side. This is called . It lets you protect a risky test with a safe one placed first:

لە &&ـدا ئەگەر لای چەپ ناڕاست بێت، دەبێت وەڵامە گشتییەکە ناڕاست بێت، بۆیە PHP تەنانەت سەیری لای ڕاست ناکات. لە ||ـدا ئەگەر لای چەپ ڕاست بێت، PHP لای ڕاست تێدەپەڕێنێت. ئەمە پێی دەوترێت . ڕێگەت دەدات تاقیکردنەوەیەکی مەترسیدار بە تاقیکردنەوەیەکی سەلامەت بپارێزیت کە پێشتر دانراوە:

safe-divide.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$a = 10;
$b = 0;
if ($b != 0 && $a / $b > 2) {
    echo "Big ratio";
} else {
    echo "Cannot divide by zero, so PHP skipped the second test.";
}
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

$b != 0 is false, so PHP never runs $a / $b, and no division by zero happens.

$b != 0 ناڕاستە، بۆیە PHP هەرگیز $a / $b جێبەجێ ناکات و هیچ دابەشکردنێک بە سفر ڕوونادات.

Logical operatorsکارپێکەرە لۆجیکییەکان

&& versus and&& بەرامبەر and

and and or do the same job as && and ||, but they have a much lower : lower even than =. This causes a classic bug:

and و or هەمان کاری && و || دەکەن، بەڵام زۆر نزمترە: تەنانەت لە =ـیش نزمترە. ئەمە بەناوبانگ دروست دەکات:

and.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "<pre>";
$x = true and false;
var_dump($x);

$y = true && false;
var_dump($y);

$z = (true and false);
var_dump($z);
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

= runs before and: PHP reads ($x = true) and false, so $x is true.

= پێش and کار دەکات: PHP دەیخوێنێتەوە بە ($x = true) and false، بۆیە $x دەبێت بە true.

Lineدێڕی 6

&& runs before =, so $y gets true && false, which is false.

&& پێش = کار دەکات، بۆیە $y ئەنجامی true && false وەردەگرێت کە false ـە.

Lineدێڕی 9

Parentheses make and work first.

کەوانەکان وا دەکەن and یەکەم کار بکات.

Quick checkپشکنینی خێراAfter $ok = true and false;, what is $ok?دوای $ok = true and false;، $ok چییە؟

You will use logical operators inside if statements in Conditional statements, with the lecture's examples ($a > $b) && ($c > $d) and !isset($a).

لەناو لە ڕستە مەرجییەکان بەکاردەهێنیت، لەگەڵ نموونەکانی وانەکە ($a > $b) && ($c > $d) و !isset($a).

String and array operatorsکارپێکەرەکانی زنجیرەنووسە و ڕیزەک

PHP has two operators: the dot . joins strings (), and .= adds a string to the end of a variable. They are explained with many examples in Strings.

PHP دوو هەیە: خاڵ . پێکەوە دەلکێنێت () و .= دەخاتە کۆتایی . بە نموونەی زۆرەوە لە زنجیرەنووسەکان ڕوون کراونەتەوە.

name.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$first = "Karwan";
$last = "Omar";
$full = $first . " " . $last;
echo $full;
echo "<br>";
$full .= "!";
echo $full;
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

Three strings joined: first name, a space, last name.

سێ پێکەوە دەلکێنرێن: ناوی یەکەم، ، ناوی کۆتایی.

Lineدێڕی 7

.= adds ! to the end.

.= نیشانەی ! دەخاتە کۆتاییەوە.

Some operators also work on . + makes the union of two arrays: it keeps every of the left array and adds only the keys of the right array that are new. == checks whether two arrays have the same ; === also requires the same order and the same types.

هەندێک لەسەر کار دەکەن. + یەکگرتنی دوو دروست دەکات: هەموو لای چەپ دەهێڵێتەوە و تەنها ئەو لای ڕاست زیاد دەکات کە نوێن. == دەپشکنێت ئایا دوو هەمان هەیە؛ === هەروەها هەمان ڕیزبەندی و هەمان جۆریشی پێویستە.

Array operators
OperatorNameناوResultئەنجام
$a + $bUnionیەکگرتن$a plus the keys of $b that $a does not have$a لەگەڵ ئەو $b کە لە $aـدا نین
$a == $bEqualیەکسانtrue if they have the same key/value pairsڕاستە ئەگەر هەمان هەبێت
$a === $bIdenticalوەک یەکtrue if same pairs, same order and same typesڕاستە ئەگەر هەمان جووت، هەمان ڕیزبەندی و هەمان جۆریان هەبێت
$a != $bNot equalیەکسان نییەopposite of ==پێچەوانەی ==
$a <> $bNot equalیەکسان نییەsame as !=وەک !=
$a !== $bNot identicalوەک یەک نییەopposite of ===پێچەوانەی ===
arrays.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$a = ["x" => 1, "y" => 2];
$b = ["y" => 20, "z" => 30];
$c = ["y" => 2, "x" => 1];

echo "<pre>";
print_r($a + $b);
var_dump($a == $c);
var_dump($a === $c);
var_dump($a != $b);
var_dump($a <> $b);
var_dump($a !== $c);
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 7

Union: "y" exists in both, so the left value (2) is kept; "z" is new and is added.

یەکگرتن: "y" لە هەردووکیاندا هەیە، بۆیە لای چەپ ⁦(2)⁩ دەمێنێتەوە؛ "z" نوێیە و زیاد دەکرێت.

Lineدێڕی 8

Same pairs in a different order: == is true.

هەمان جووت بە ڕیزبەندییەکی جیاواز: == ڕاستە.

Lineدێڕی 9

=== also checks the order, so it is false.

=== ڕیزبەندیش دەپشکنێت، بۆیە ناڕاستە.

Quick checkپشکنینی خێرا$a = ["x" => 1]; $b = ["x" => 9, "y" => 2]; What is $a + $b?$a = ["x" => 1]; $b = ["x" => 9, "y" => 2]; $a + $b دەبێت بە کام ؟

Two shortcut operators: ?: and ??دوو کارپێکەری کورتکراوە: ?: و ??

The condition ? a : b gives a when the condition is true and b when it is false. The $x ?? "default" gives $x if it exists and is not null, otherwise the default. Both are short forms of an if ... else and are explained further in Conditional statements.

condition ? a : b کاتێک ڕاست بێت a دەدات و کاتێک ناڕاست بێت b. $x ?? "default" ئەگەر $x هەبێت و null نەبێت $x دەدات، ئەگەر نا . هەردووکیان شێوەی کورتی if ... elseن و زیاتر لە ڕستە مەرجییەکان ڕوون دەکرێنەوە.

shortcuts.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$age = 16;
echo $age >= 18 ? "Adult" : "Minor";
echo "<br>";
$name = null;
echo $name ?? "Guest";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

16 >= 18 is false, so the second value "Minor" is printed.

⁦16 >= 18⁩ ناڕاستە، بۆیە دووەم "Minor" چاپ دەکرێت.

Lineدێڕی 6

$name is null, so the default "Guest" is used.

$name بریتییە لە null، بۆیە "Guest" بەکاردێت.

Operator precedence: who goes first?پێشینەیی کارپێکەرەکان: کێ یەکەم کار دەکات؟

When an expression has several operators, PHP does not simply work from left to right. Each operator has a rank called its . Higher-ranked operators run first, just like in school maths, where multiplication comes before addition: 2 + 3 * 4 is 14, not 20. When two operators have the same rank, their associativity decides: most go left to right, but ** and the assignment operators go right to left.

کاتێک چەند تێدایە، PHP بە سادەیی لە چەپەوە بۆ ڕاست کار ناکات. هەر پلەیەکی هەیە کە پێی دەوترێت . ئەو پلەیان بەرزترە یەکەم کار دەکەن، ڕێک وەک بیرکاریی قوتابخانە کە لێکدان پێش کۆکردنەوە دێت: 2 + 3 * 4 دەکاتە ⁦14⁩، نەک ⁦20⁩. کاتێک دوو هەمان پلەیان هەبێت، ئاراستەی جێبەجێکردن بڕیار دەدات: زۆربەیان لە چەپەوە بۆ ڕاست دەڕۆن، بەڵام ** و لە ڕاستەوە بۆ چەپ.

Definitionپێناسە

The rules that decide which operator runs first when an expression has several. * and / come before + and -, so 2 + 3 * 4 is 14; use parentheses to change the order.

ئەو یاسایانەن کە دیاری دەکەن کام یەکەم جێبەجێ دەکرێت کاتێک چەند کارپێکەرێکی تێدایە. * و / پێش + و - دێن، بۆیە 2 + 3 * 4 دەکاتە ⁦14⁩؛ بۆ گۆڕینی ڕیزبەندییەکە کەوانە بەکاربهێنە.

Precedence of the operators in this lecture, from highest to lowest (PHP 8)پێشینەیی ئەو لەم وانەیەدان، لە بەرزترینەوە بۆ نزمترین ⁦(PHP 8)⁩
Operators (highest first) (بەرزترین لە سەرەوە)MeaningواتاDirectionئاراستەExampleنموونە
**exponentتوانright to leftلە ڕاستەوە بۆ چەپ2 ** 3 ** 2 → 512
++ -- - (int) …increment, decrement, negation, type casts، ، نەرێکردن، —-3 ** 2 → -9
!logical notنای لۆجیکی—!true → false
* / %multiply, divide, remainderلێکدان، دابەشکردن، left to rightلە چەپەوە بۆ ڕاست100 / 10 / 2 → 5
+ -add, subtractکۆکردنەوە، لێدەرکردنleft to rightلە چەپەوە بۆ ڕاست10 - 4 - 3 → 3
.string concatenationleft to rightلە چەپەوە بۆ ڕاست"Sum: " . 1 + 2 → "Sum: 3"
< <= > >=comparisonبەراوردکردنcannot be chainedناکرێت بە زنجیر بنووسرێن5 + 3 > 7 → true
== != === !== <> <=>equalityیەکسانیcannot be chainedناکرێت بە زنجیر بنووسرێن—
&&logical andو-ی لۆجیکیleft to rightلە چەپەوە بۆ ڕاست—
||logical orیان-ی لۆجیکیleft to rightلە چەپەوە بۆ ڕاست—
??null coalescingright to leftلە ڕاستەوە بۆ چەپ—
? :ternarycannot be chained without bracketsبەبێ کەوانە ناکرێت بە زنجیر بنووسرێت—
= += -= *= /= .= %= **= ??=assignmentright to leftلە ڕاستەوە بۆ چەپ$b = $c = 0
andlogical and (low)و-ی لۆجیکی (نزم)left to rightلە چەپەوە بۆ ڕاست—
xorlogical xorxor-ی لۆجیکیleft to rightلە چەپەوە بۆ ڕاست—
orlogical or (low)یان-ی لۆجیکی (نزم)left to rightلە چەپەوە بۆ ڕاست—
precedence.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo 2 + 3 * 4;
echo "<br>";
echo (2 + 3) * 4;
echo "<br>";
echo 10 - 4 - 3;
echo "<br>";
echo 2 ** 3 ** 2;
echo "<br>";
echo -3 ** 2;
echo "<br>";
echo "Sum: " . 1 + 2;
echo "<br>";
var_dump(5 + 3 > 7);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

* before +: 2 + 12 = 14.

* پێش +: ⁦2 + 12 = 14⁩.

Lineدێڕی 4

Brackets first: 5 * 4 = 20.

سەرەتا کەوانەکان: ⁦5 * 4 = 20⁩.

Lineدێڕی 6

Same rank, left to right: (10 - 4) - 3 = 3.

هەمان پلە، لە چەپەوە بۆ ڕاست: ⁦(10 - 4) - 3 = 3⁩.

Lineدێڕی 8

** goes right to left: 2 (3 2) = 2 ** 9 = 512.

** لە ڕاستەوە بۆ چەپ دەڕوات: 2 (⁦3⁩ ⁦2) = 2 ** 9 = 512⁩.

Lineدێڕی 10

** is stronger than the minus sign: -(3 ** 2) = -9.

** لە نیشانەی کەم بەهێزترە: -⁦(3 ** 2) = -9⁩.

Lineدێڕی 12

In PHP 8, + runs before .: "Sum: " . (1 + 2).

لە ⁦PHP 8⁩دا + پێش . کار دەکات: "⁦Sum: " . (1 + 2)⁩.

Lineدێڕی 14

Arithmetic runs before comparison: (5 + 3) > 7.

هەژمارکردنی ژمێرەیی پێش بەراوردکردن کار دەکات: ⁦(5 + 3) > 7⁩.

Quick checkپشکنینی خێراWhat does echo 2 + 3 * 4; print?echo 2 + 3 * 4; چی چاپ دەکات؟

Common mistakesئەو هەڵانەی زۆر دەکرێن

  1. = instead of ==. if ($x = 5) stores 5 and is always true. Compare with == or ===.
  2. == when you meant ===. 5 == "5" is true. Use === when the type matters.
  3. A missing $. * var2 makes PHP look for a constant and stop. Every variable needs its $.
  4. $--a or $++a. The operator goes before the $: --$a, ++$a.
  5. Forgetting that postfix gives the old value. echo $x++; prints the value before adding 1.
  6. Expecting / to give a whole number. 10 / 4 is 2.5. Use intdiv() for whole-number division.
  7. Dividing by zero. / 0 and % 0 stop the script. Check the divisor first, for example with $b != 0 && ....
  8. Using % with decimals. % works on integers; 7.5 % 2 loses the .5 (and PHP shows a deprecation notice). Use fmod(7.5, 2) for decimals.
  9. Writing 18 <= $age <= 30. Comparisons cannot be chained. Write 18 <= $age && $age <= 30.
  10. and/or with =. $x = true and false; sets $x to true. Use &&/|| or parentheses.
  11. Using + to join strings. That is the dot: "a" . "b".
  1. = لە جیاتی ==. if ($x = 5) ژمارە 5 هەڵدەگرێت و هەمیشە ڕاستە. بە == یان === بەراورد بکە.
  2. == کاتێک مەبەستت === بوو. 5 == "5" ڕاستە. کاتێک جۆرەکە گرنگە === بەکاربهێنە.
  3. $ـی ونبوو. * var2 وا دەکات PHP بەدوای بگەڕێت و بوەستێت. هەموو $ـی خۆی پێویستە.
  4. $--a یان $++a. پێش $ دێت: --$a، ++$a.
  5. لەبیرچوونی ئەوەی پاشگر دەدات. echo $x++; پێش ئەوەی 1 زیاد بکات چاپ دەکات.
  6. چاوەڕوانی لە /. 10 / 4 دەکاتە ⁦2.5⁩. بۆ دابەشکردنی تەواو intdiv() بەکاربهێنە.
  7. دابەشکردن بە سفر. / 0 و % 0 دەوەستێنن. سەرەتا دابەشکەرەکە بپشکنە، بۆ نموونە بە $b != 0 && ....
  8. بەکارهێنانی % لەگەڵ ژمارەی دەیدەیی. % لەسەر کار دەکات؛ 7.5 % 2 بەشی .5 لەدەست دەدات (و PHP ئاگادارییەکی پیشان دەدات). بۆ ژمارەی دەیدەیی fmod(7.5, 2) بەکاربهێنە.
  9. نووسینی 18 <= $age <= 30. بەراوردەکان ناکرێت بە زنجیر بنووسرێن. بنووسە 18 <= $age && $age <= 30.
  10. and/or لەگەڵ =. $x = true and false; $x دەکات بە true. &&/|| یان کەوانە بەکاربهێنە.
  11. بەکارهێنانی + بۆ لکاندنی . ئەوە کاری خاڵە: "a" . "b".

Exercises and lab tasksڕاهێنان و ئەرکەکانی تاقیگە

Predict every output on paper first, then type the code and run it with XAMPP.

سەرەتا هەموو لەسەر کاغەز پێشبینی بکە، پاشان کۆدەکە بنووسە و بە XAMPP کاری پێ بکە.

ExerciseڕاهێنانLab 2, Example 5: arithmetic operationsتاقیگەی 2، نموونەی 5: هەژمارکردنی ژمێرەیی

Predict the five numbers this program prints. Then change $y to 3 and predict again.

ئەو پێنج ژمارەیەی ئەم چاپیان دەکات پێشبینی بکە. پاشان $y بگۆڕە بۆ 3 و دیسان پێشبینی بکە.

arithmetic.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 10;
$y = 4;
echo($x + $y);
echo "<br>";
echo($x - $y);
echo "<br>";
echo($x * $y);
echo "<br>";
echo($x / $y);
echo "<br>";
echo($x % $y);
?>
Hintئاماژە

/ can give a decimal number. % gives what is left after dividing.

/ دەتوانێت ژمارەی دەیدەیی بدات. % ئەوە دەدات کە دوای دابەشکردن دەمێنێتەوە.

Show answerوەڵامەکە پیشان بدە
arithmetic.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 10;
$y = 4;
echo($x + $y);
echo "<br>";
echo($x - $y);
echo "<br>";
echo($x * $y);
echo "<br>";
echo($x / $y);
echo "<br>";
echo($x % $y);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 10

10 / 4 = 2.5 (a float).

⁦10 / 4⁩ دەکاتە ⁦2.5⁩ ().

Lineدێڕی 12

10 = 2 × 4 + 2, so the remainder is 2.

⁦10 = 2 × 4 +⁩ 2، بۆیە 2ـە.

With $y = 3:

بە $y = 3:

arithmetic.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 10;
$y = 3;
echo($x + $y);
echo "<br>";
echo($x - $y);
echo "<br>";
echo($x * $y);
echo "<br>";
echo($x / $y);
echo "<br>";
echo($x % $y);
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 10

10 / 3 never ends; PHP prints 14 significant digits.

⁦10 / 3⁩ هەرگیز کۆتایی نایەت؛ ⁦PHP 14⁩ ژمارەی گرنگ چاپ دەکات.

Lineدێڕی 12

10 = 3 × 3 + 1, so the remainder is 1.

⁦10 = 3 × 3 + 1⁩، بۆیە 1ـە.

ExerciseڕاهێنانLab 2, Example 6: assignment operatorsتاقیگەی 2، نموونەی 6: کارپێکەرەکانی دانانی نرخ

Predict the six numbers. Then rewrite every compound operator in its long form (for example $x += 30; becomes $x = $x + 30;) and check that the output does not change.

شەش ژمارەکە پێشبینی بکە. پاشان هەموو لێکدراو بە شێوە درێژەکەی بنووسەرەوە (بۆ نموونە $x += 30; دەبێت بە $x = $x + 30;) و دڵنیا ببەوە کە ناگۆڕێت.

assignment.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 10;
echo $x;
echo "<br>";

$x = 20;
$x += 30;
echo $x;
echo "<br>";

$x = 50;
$x -= 20;
echo $x;
echo "<br>";

$x = 5;
$x *= 25;
echo $x;
echo "<br>";

$x = 50;
$x /= 10;
echo $x;
echo "<br>";

$x = 100;
$x %= 15;
echo $x;
?>
Show answerوەڵامەکە پیشان بدە
assignment.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 10;
echo $x;
echo "<br>";

$x = 20;
$x += 30;
echo $x;
echo "<br>";

$x = 50;
$x -= 20;
echo $x;
echo "<br>";

$x = 5;
$x *= 25;
echo $x;
echo "<br>";

$x = 50;
$x /= 10;
echo $x;
echo "<br>";

$x = 100;
$x %= 15;
echo $x;
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 7

20 + 30 = 50

⁦20 + 30⁩ دەکاتە ⁦50⁩

Lineدێڕی 12

50 - 20 = 30

⁦50 - 20⁩ دەکاتە ⁦30⁩

Lineدێڕی 17

5 × 25 = 125

⁦5 × 25⁩ دەکاتە ⁦125⁩

Lineدێڕی 22

50 / 10 = 5 (exact, so an integer)

⁦50 / 10⁩ دەکاتە 5 (تەواوە، بۆیە )

Lineدێڕی 27

100 = 6 × 15 + 10, remainder 10

⁦100 = 6 × 15 + 10⁩، ⁦10⁩

The long form gives exactly the same output:

شێوە درێژەکە ڕێک هەمان دەدات:

assignment-long.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 10;
echo $x;
echo "<br>";

$x = 20;
$x = $x + 30;
echo $x;
echo "<br>";

$x = 50;
$x = $x - 20;
echo $x;
echo "<br>";

$x = 5;
$x = $x * 25;
echo $x;
echo "<br>";

$x = 50;
$x = $x / 10;
echo $x;
echo "<br>";

$x = 100;
$x = $x % 15;
echo $x;
?>
ExerciseڕاهێنانLab 2, Example 8: increment and decrementتاقیگەی 2، نموونەی 8: زیادکردن و کەمکردنەوە

Each block starts again with $x = 10. Predict the eight numbers. Which blocks print the old value first?

هەر بلۆکێک دیسان بە $x = 10 دەست پێ دەکات. هەشت ژمارەکە پێشبینی بکە. کام بلۆکانە سەرەتا چاپ دەکەن؟

increment.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 10;
echo ++$x;
echo "<br>";
echo $x;
echo "<hr>";

$x = 10;
echo $x++;
echo "<br>";
echo $x;
echo "<hr>";

$x = 10;
echo --$x;
echo "<br>";
echo $x;
echo "<hr>";

$x = 10;
echo $x--;
echo "<br>";
echo $x;
?>
Hintئاماژە

Look where the ++ or -- is: before the variable (change first) or after it (use first).

سەیر بکە ++ یان -- لە کوێیە: پێش (سەرەتا گۆڕین) یان دوای (سەرەتا بەکارهێنان).

Show answerوەڵامەکە پیشان بدە
increment.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 10;
echo ++$x;
echo "<br>";
echo $x;
echo "<hr>";

$x = 10;
echo $x++;
echo "<br>";
echo $x;
echo "<hr>";

$x = 10;
echo --$x;
echo "<br>";
echo $x;
echo "<hr>";

$x = 10;
echo $x--;
echo "<br>";
echo $x;
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

Pre-increment: 11, then $x is 11.

پێش-: ⁦11⁩، پاشان $x دەکاتە ⁦11⁩.

Lineدێڕی 9

Post-increment: prints the old value 10, then $x is 11.

پاش-: ⁦10⁩ چاپ دەکات، پاشان $x دەکاتە ⁦11⁩.

Lineدێڕی 15

Pre-decrement: 9, then $x is 9.

پێش-: 9، پاشان $x دەکاتە 9.

Lineدێڕی 21

Post-decrement: prints 10, then $x is 9.

پاش-: ⁦10⁩ چاپ دەکات، پاشان $x دەکاتە 9.

The second and fourth blocks (postfix $x++ and $x--) print the old value first. After every block the variable has changed by exactly 1.

بلۆکی دووەم و چوارەم (پاشگری $x++ و $x--) سەرەتا چاپ دەکەن. دوای هەر بلۆکێک ڕێک بە 1 گۆڕاوە.

ExerciseڕاهێنانFix the decrementکەمکردنەوەکە چاک بکەرەوە

This line from the course notes does not run: echo $--a;. Fix it so that it prints 7 when $a is 8, and explain why the original is wrong.

ئەم دێڕەی تێبینییەکانی کۆرسەکە کار ناکات: echo $--a;. چاکی بکەرەوە بۆ ئەوەی کاتێک $a یەکسان بێت بە 8 ژمارە 7 چاپ بکات و ڕوونی بکەرەوە بۆچی ئەسڵەکەی نادروستە.

Show answerوەڵامەکە پیشان بدە
fix.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$a = 8;
echo --$a;
echo "<br>";
echo $a;
?>

-- must be written before the whole variable name, including the $. Pre-decrement (--$a) takes 1 away first, so echo prints 7.

-- دەبێت پێش هەموو ناوی بنووسرێت، $ـیشی لەگەڵدا. پێش- (--$a) سەرەتا 1 کەم دەکاتەوە، بۆیە echo ژمارە 7 چاپ دەکات.

Exercises and lab tasksڕاهێنان و ئەرکەکانی تاقیگە

More practiceڕاهێنانی زیاتر

ExerciseڕاهێنانEven or odd?جووت یان تاک؟

Write a program that prints whether the number in $n is even or odd. Test it with 7 and with 10.

بنووسە کە چاپ بکات ئایا ژمارەکەی ناو $n جووتە یان تاک. بە 7 و ⁦10⁩ تاقی بکەرەوە.

Hintئاماژە

An even number divided by 2 leaves no remainder.

ژمارەی جووت کاتێک دابەش 2 دەکرێت هیچی لێ نامێنێتەوە.

Show answerوەڵامەکە پیشان بدە
even-odd.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$n = 7;
if ($n % 2 == 0) {
    echo "$n is even";
} else {
    echo "$n is odd";
}
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

$n % 2 is 0 for even numbers and 1 for odd ones.

$n % 2 بۆ ژمارەی جووت 0ـە و بۆ تاک 1ـە.

With $n = 10 the program prints 10 is even.

بە $n = 10 10 is even چاپ دەکات.

ExerciseڕاهێنانShopping totalکۆی کڕین

Karwan buys 3 notebooks at 1,500 dinars and 2 pens at 750 dinars. The shop gives a 10% discount. Use += and *= to calculate the total before and after the discount.

کاروان 3 دەفتەر بە ⁦1,500⁩ دینار و 2 پێنووس بە ⁦750⁩ دینار دەکڕێت. دوکانەکە ⁦10%⁩ داشکاندن دەکات. بە += و *= کۆی گشتی پێش و دوای داشکاندن هەژمار بکە.

Show answerوەڵامەکە پیشان بدە
shop.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$total = 0;
$total += 3 * 1500;   // three notebooks
$total += 2 * 750;    // two pens
echo "Before discount: $total dinars<br>";
$total *= 0.9;        // 10% discount
echo "After discount: $total dinars";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3-4

+= adds each item to the running total: 4,500 + 1,500 = 6,000.

+= هەر شتێک دەخاتە سەر کۆکە: ⁦4,500 + 1,500 = 6,000⁩.

Lineدێڕی 6

Multiplying by 0.9 keeps 90%: 6,000 × 0.9 = 5,400.

لێکدان لە ⁦0.9⁩، ⁦90%⁩ی کۆکە دەهێڵێتەوە: ⁦6,000 × 0.9 = 5,400⁩.

Summary and reviewپوختە و پێداچوونەوە

  • Arithmetic: + - * / % **. / can give a float; % gives the remainder; dividing by zero stops the script.
  • Assignment: = stores a value. +=, -=, *=, /=, %=, **= and .= calculate and store in one step.
  • ++ and -- add or take away 1. Prefix (++$x) changes first; postfix ($x++) gives the old value first.
  • Comparison operators give true/false. == compares values after conversion; === also compares types. <=> gives -1, 0 or 1.
  • Logical operators &&, ||, !, xor (and the low-precedence and, or) combine conditions; PHP stops as soon as it knows the answer.
  • Precedence decides the order: **, then * / %, then + -, then ., comparisons, &&, ||, assignment, then and, xor, or. When unsure, use parentheses.
  • ژمێرەیی: + - * / % **. / دەتوانێت بدات؛ % دەدات؛ دابەشکردن بە سفر دەوەستێنێت.
  • : = هەڵدەگرێت. +=، -=، *=، /=، %=، **= و .= بە یەک هەنگاو هەژمار دەکەن و هەڵدەگرن.
  • ++ و -- یەک زیاد یان کەم دەکەن. پێشگر (++$x) سەرەتا دەگۆڕێت؛ پاشگر ($x++) سەرەتا دەدات.
  • true/false دەدەن. == دوای بەراورد دەکات؛ === جۆرەکانیش بەراورد دەکات. <=> یەکێک لە ⁦-1⁩، 0 یان 1 دەدات.
  • &&، ||، !، xor (و and، or بە پێشینەیی نزم) پێکەوە دەبەستن؛ PHP هەر کە وەڵامەکەی زانی دەوەستێت.
  • ڕیزبەندییەکە دیاری دەکات: **، پاشان * / %، پاشان + -، پاشان .، بەراوردەکان، &&، ||، ، پاشان and، xor، or. کاتێک دڵنیا نیت، کەوانە بەکاربهێنە.
Review questionsپرسیارەکانی پێداچوونەوە
What is the difference between an operator and an operand?جیاوازیی نێوان کارپێکەر و کارپێکراو چییە؟

The operator is the symbol that does the work (+); the operands are the values it works on (2 and 3 in 2 + 3).

ئەو هێمایەیە کە کارەکە دەکات (+)؛ ئەو کە کاریان لەسەر دەکرێت (2 و 3 لە 2 + 3ـدا).

Why does echo 10 / 4; print 2.5 but echo 10 / 5; print 2?بۆچی echo 10 / 4; ژمارە ⁦2.5⁩ چاپ دەکات بەڵام echo 10 / 5; ژمارە 2؟

/ returns an integer when the division is exact and a float when it is not.

/ کاتێک دابەشکردنەکە تەواو بێت دەگەڕێنێتەوە و کاتێک تەواو نەبێت .

What does $x .= "!"; do, and which family does .= belong to?$x .= "!"; چی دەکات و .= سەر بە کام خێزانە؟

It adds ! to the end of $x. It is an assignment operator for strings.

! دەخاتە کۆتایی $xـەوە. بۆ .

If $a = 3, what do echo ++$a; and echo $a++; print (each starting from 3)?ئەگەر $a = 3 بێت، echo ++$a; و echo $a++; چی چاپ دەکەن (هەریەکەیان لە 3ـەوە دەست پێ بکات)؟

++$a prints 4; $a++ prints 3. In both cases $a is 4 afterwards.

++$a ژمارە 4 چاپ دەکات؛ $a++ ژمارە 3. لە هەردوو حاڵەتدا دواتر $a دەبێت بە 4.

Why is echo $--a; an error?بۆچی echo $--a; هەڵەیە؟

The -- must come before the whole variable (--$a) or after it ($a--); it cannot sit between $ and the name. PHP reports a parse error.

-- دەبێت پێش هەموو (--$a) یان دوای ($a--) بێت؛ ناتوانێت لە نێوان $ و ناوەکەدا بێت. PHP ڕادەگەیەنێت.

What do 5 == "5" and 5 === "5" return, and why?5 == "5" و 5 === "5" چی دەگەڕێننەوە و بۆچی؟

true and false. == converts the string to a number first; === also requires the same type.

true و false. == سەرەتا دەکات بە ژمارە؛ === هەمان جۆریشی پێویستە.

Are >, <, == and != boolean (logical) operators?ئایا >، <، == و != کارپێکەرە لۆجیکییەکانن؟

No. They are comparison operators that produce booleans. The logical operators are &&, ||, !, and, or and xor.

نەخێر. ئەمانە کە بەرهەم دەهێنن. بریتین لە &&، ||، !، and، or و xor.

What is the value of ((1 + 2 + 3) * 4) / 2 - 5?نرخی ((1 + 2 + 3) * 4) / 2 - 5 چەندە؟

7: brackets give 6, then 6 × 4 = 24, 24 / 2 = 12, and 12 - 5 = 7.

7: کەوانەکان 6 دەدەن، پاشان ⁦6 × 4 = 24⁩، ⁦24 / 2 = 12⁩ و ⁦12 - 5 = 7⁩.

Why can if ($b != 0 && $a / $b > 2) never divide by zero?بۆچی if ($b != 0 && $a / $b > 2) هەرگیز بە سفر دابەش ناکات؟

Because of short-circuit evaluation: when $b != 0 is false, PHP does not run the right side of &&.

بەهۆی : کاتێک $b != 0 ناڕاست بێت، PHP لای ڕاستی && جێبەجێ ناکات.

Videoڤیدیۆ

Watch a videoسەیری ڤیدیۆیەک بکە

A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.

7 | The PHP Operators You Need to Know! | 2023 | Learn PHP Full Course for BeginnersDani Krossing · Englishئینگلیزی · 82K viewsبینین · 1.7K likesلایک

A calm overview of PHP operators with examples: string, arithmetic, assignment, comparison and logical operators, and increment and decrement.

ناساندنێکی ئارام بۆ بە نموونەوە: ، ، ، و ، لەگەڵ و .

Overview of every operator group in this lesson.

تێڕوانینێکی گشتی بۆ هەموو گرووپەکانی لەم وانەیەدا.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Conditional Statements: if, else, elseif and switchڕستە مەرجییەکان: if و else و elseif و switch

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.