PHP Lesson 4 – Operators
Binary
This operator It includes transactions greater than and less than. “<“, “<=”, “>”, “>=” operators are used.
<?php var_dump(1 5); // Returns FALSE.
Ternary
This operator covers equality checking operations.
“==” operator Checks whether the values are equal. For example string with a value of 1 integer For a value of 1 TRUE returns the value.
“===” operator Checks whether the data types are equal as well as the values. String with a value of 1 integer For a value of 1 FALSE will return the value.
<?php var_dump("1" == 1); // TRUE değeri verir. var_dump("10" === 10); // FALSE değeri verir. Çünkü veri tipleri eşit değil.
Concatenation
It is the data concatenation operator. “.” operator is used.
<?php $isim = "Erhan"; $soyad = "Kılıç"; var_dumo($isim . " " . $soyad); // "Erhan Kılıç" değeri döndürecektir.
Arithmetic
These are the operators used for arithmetic operations.
“+” operator mathematically adds integer data and concatenates string data.
“-“ operator mathematically subtracts integer data from each other.
“/” operator divides integer data mathematically.
“*” operator mathematically multiplies integer data together.
“%” The operator returns the remainder when integer data is divided by each other. For example, 10%2 returns the value 0, and 10%3 returns the value 1.
“++” operator increases integer data by 1.
<?php var_dump(10+5); // 15 değeri döndürecektir. var_dump("10"+"5"); // 105 değeri döndürecektir. var_dump(10-5); // 5 değeri döndürecektir. var_dump(10/2); // 5 değeri döndürecektir. var_dump(10*2); // 20 değeri döndürecektir. var_dump(10%4); // 2 değeri döndürecektir. var_dump(10++); // 11 değğeri döndürecektir.
Casting
These are the operators used to determine data types. “int”, “string”, “bool” operators are used.
<?php $int = (int)"10"; // String 10 olan veriyi integer 10 yapar. $string = (string)255; // İnteger 255 olan veriyi string 255 yapar. $boolean = (bool)"bool"; // String veriyi TRUE'ya yani 1'e çevirir.
Assignments
They are assignment operators. They are used to determine or change the contents of a variable. “=”, “+=”, “.=” operators are used.
<?php $degisken = "deger"; $degisken += " birleştirme"; $degisken .= ", ikinci birleştirme";
Logical Operators
In Turkish, they are operators meaning "and" and "or". “&&”, “AND”, “||”, “OR” operators are used.
<?php $a = TRUE; $b = TRUE; $c = FALSE; var_dump ($a and $b); // true sonucu döner. var_dump ($a && $c); // false sonucu döner. var_dump($a or $b || $c); // true sonucu döner.
Next Lesson: Php Lesson 5 – Conditions