expressions and control flow. expressions an expression is a combination of values, variables,...
DESCRIPTION
Boolian Example 4.1TRANSCRIPT
![Page 1: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/1.jpg)
Expressions andControl Flow
![Page 2: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/2.jpg)
Expressions
• An expression is a combination of values, variables, operators, and functions that results in a value
y = 3(abs(2x) + 4)
• which in PHP would be: $y = 3 * (abs(2*$x) + 4);
![Page 3: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/3.jpg)
Boolian
• Example 4.1
• <?php• echo "a: [" . (20 > 9) . "]<br />";• echo "b: [" . (5 == 6) . "]<br />";• echo "c: [" . (1 == 0) . "]<br />";• echo "d: [" . (1 == 1) . "]<br />";• ?>
![Page 4: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/4.jpg)
Literals and Variables
• Example 4-3. Five types of literals • <?php
$myname = "Brian"; $myage = 37;echo "a: " . 73echo "b: " . "Hello" echo "c: " . FALSE echo "d: " . $myname echo "e: " . $myage ?>
. "<br />"; // Numeric literal
. "<br />"; // String literal
. "<br />"; // Constant literal
. "<br />"; // Variable string literal . "<br />"; // Variable numeric literal
![Page 5: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/5.jpg)
Expression Statement
• Example 4-4. An expression and a statement • <?php
$days_to_new_year = 366 - $day_number; // Expression if ($days_to_new_year < 30){
• echo "Not long now till new year"; // Statement } • ?>
![Page 6: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/6.jpg)
Operators
• Table 4-1. PHP operator types • Operator Description Example • Arithmetic Array Assignment Bitwise • Basic mathematics
Array unionAssign valuesManipulate bits within bytes
• $a + $b $a + $b $a = $b + 23 12 ^ 9
![Page 7: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/7.jpg)
PHP operator types
• Table 4-1. PHP operator types • Operator Description Example • Arithmetic Array Assignment Bitwise • Basic mathematics
Array unionAssign valuesManipulate bits within bytes
• $a + $b $a + $b $a = $b + 23 12 ^ 9
![Page 8: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/8.jpg)
Operator Precedence
• If all operators had the same precedence, they would be processed in the order in which they are encountered. In fact, many operators do have the same precedence, so let’s look at a few in Example 4-5.
• Example 4-5. Three equivalent expressions • 1 +2+3-4+5• 2 -4+5+3+1 • 5 +2-4+1+3
![Page 9: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/9.jpg)
Operators
• PHP’s operators in order of precedence from high to low. • Table 4-2. The precedence of PHP operators (high to
low)
![Page 10: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/10.jpg)
Operators cont
![Page 11: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/11.jpg)
Associativity
![Page 12: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/12.jpg)
Relational Operators
• the equality operator is == (two equals signs)• Example 4-12. Assigning a value and testing for equality
<?php$month = "March";if ($month == "March") echo "It's springtime";?>
• Returning either TRUE or FALSE, the equality operator enables you to test for conditions using, for example, an if statement
![Page 13: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/13.jpg)
Comparison operators
• you can test for more than just equality and inequality. PHP also gives you > (is greater than), < (is less than), >= (is greater than or equal to), and <= (is less than or equal to)
• Example 4-15. The four comparison operators• <?php• $a = 2; $b = 3;• if ($a > $b) echo "$a is greater than $b<br />";• if ($a < $b) echo "$a is less than $b<br />";• if ($a >= $b) echo "$a is greater than or equal to $b<br />";• if ($a <= $b) echo "$a is less than or equal to $b<br />";• ?>
![Page 14: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/14.jpg)
Logical operators
![Page 15: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/15.jpg)
Conditionals
![Page 16: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/16.jpg)
Conditionals
• The if Statement
• The else Statement
• The elseif Statement
• The switch Statement
![Page 17: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/17.jpg)
Conditionals
![Page 18: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/18.jpg)
Conditional Switch Statement
![Page 19: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/19.jpg)
The ? Operator
• Example 4-26. Using the ? operator<?phpecho $fuel <= 1 ? "Fill tank now" : "There's enough
fuel";?>
![Page 20: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/20.jpg)
Looping
![Page 21: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/21.jpg)
Loopie
• do...while Loops• for Loops• Breaking Out of a Loop• The continue Statement
![Page 22: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/22.jpg)
Implicit and Explicit Casting
![Page 23: Expressions and Control Flow. Expressions An expression is a combination of values, variables, operators, and functions that results in a value y = 3(abs(2x)](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b207f8b9ab059995105/html5/thumbnails/23.jpg)
PHP Dynamic Linking
• You can split your website up into sensible sections of PHP code, each one self-contained, and therefore treat yourself to a much easier future developing each new feature and maintaining old ones
• Dynamic Linking in Action Wordpress