50 likes | 291 Vues
Dive into PHP operators with this comprehensive lesson covering assignment operators, arithmetic operations, and more. Learn how to effectively use grouping symbols and concatenation with periods. Explore error control tactics to manage output gracefully, and master increment/decrement operations to manipulate variables efficiently. Grasp the essentials of comparison and logical operators, along with practical examples to solidify understanding. This guided approach ensures you will confidently apply these fundamental concepts in your PHP programming endeavors.
E N D
PHP Operators Lesson 5
Operators 1. = the assignment operator 2. +, -, *, / you can use parenthesis as grouping symbols to makes your formula more readable Ex. $root=(-$b+ (b*b-4*a*c))/2*a; 3. % modulus operator (returns the remainder when 2 numbers are divided) Ex. $remainder=10%3 (will return 1) 4. . (period) concatenator. This can be combined with = sign Ex. $food = $food . “burger”; is the same as $food .=“burger”;
5. @ error control operator. This is used so php wont display output. Use them with caution Ex. @quotient = 10/0; This is the error but since there is a @ prefixed in the variable name, therefore the error wont be displayed. Makes findings errors a difficult process. 6. Increment (++) and decrement (--) operators. This is placed either before or after a variable. 7. Prefixing ++$a will increment the value then return the value (which is now incremented) --$a will decrement the value then return the value (which is now decremented)
8. Postfixing Sa++ will return the value first then increment the value $a– will return the value first then decrement the value 9. Comparison Operators: ==, !=, <, <=, >, >= - returns a Boolean value - i.e. returns either true or false - or returns either 1 or 0 - often used as conditions in conditional statements such as IF-THEN-ELSE, or looping statements 10. Logical operators: and, &&, or, ||, xor, !
Activity <?php //save as prefixandpostfix.php $a = 5; $b = 10; print ++$a; print “<br>”; print $a; print “<br>”; print $b++; print “<br>”; print $b; ?>