Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hello world <?php print "hello world"; ?>. Variables A variable consists of a name that you can choose, preceded by a dollar ($) sign. Some legal variables.

Similar presentations


Presentation on theme: "Hello world <?php print "hello world"; ?>. Variables A variable consists of a name that you can choose, preceded by a dollar ($) sign. Some legal variables."— Presentation transcript:

1 Hello world <?php print "hello world"; ?>

2 Variables A variable consists of a name that you can choose, preceded by a dollar ($) sign. Some legal variables $a; $a_longish_variable_name; $_2453; $sleepyZZZZ;

3 Data Types PHP is loosely typed, which means it calculates data types as data is assigned to each variable You can use PHP's built-in function gettype () to acquire the type of any variable

4 An operator is a symbol or series of symbols that, when used with values, performs an action and usually produces a new value. An operand is a value used in conjunction with an operator. There are usually two operands to one operator.

5 The Assignment Operator $name = "matt"; Arithmetic Operators + - * / %

6 The Concatenation Operator "hello"." world" is equivalent to "hello world" $centimeters = 212; print "the width is ".($centimeters/100)." meters";

7 Logical Operators true || false returns true. true && false returns false.

8 CONSTANT define ("CONSTANT_NAME", 42); <?php define ("USER", "Gerald"); print "Welcome".USER; ?>

9 The if Statement if (expression) { // code to execute if the expression evaluates to true } Using the else Clause with the if Statement if (expression) { // code to execute if the expression evaluates to true } else { // code to execute in all other cases }

10 Using the else if Clause with the if Statement if ( expression ) { // code to execute if the expression evaluates to true } else if ( another expression ) { // code to execute if the previous expression failed // and this one evaluates to true } else { // code to execute in all other cases }

11 The switch Statement switch (expression) { case result1: // execute this if expression results in result1 break; case result2: // execute this if expression results in result2 break; default: // execute this if no break statement // has been encountered hitherto }

12 Loops while ( expression ) { // do something } <?php $counter = 1; while ( $counter <= 12 ) { print "$counter times 2 is ".($counter*2)." "; $counter++; } ?>

13 The do...while Statement do { // code to be executed } while (expression); <?php 11: $num = 1; 12: do { 13: print "Execution number: $num \n"; 14: $num++; 15: } while ( $num > 200 && $num < 400 ); 16: ?>

14 The for Statement for ( initialization expression; test expression; modification expression ) { // code to be executed } <?php 11: for ( $counter=1; $counter<=12; $counter++ ) { 12: print "$counter times 2 is".($counter*2)." "; 13: }

15 Nesting Two for Loops * ** *** **** ***** Triangle Downward triangle

16 Function 10: <?php 11: function bighello() { 12: print " HELLO! "; 13: } 14: bighello(); 15: ?>

17 Function That Returns a Value 10: <?php 11: function addNums( $firstnum, $secondnum ) { 12: $result = $firstnum + $secondnum; 13: return $result; 14: } 15: print addNums(3,5); 16: // will print "8" 17: ?>

18 Array $users = array ("Bert", "Sharon", "Betty", "Harry"); You can now access the third element in the $user array by using the index 2: print $users[2];

19 Assignment Update and delete Designing Studio 3d max Maya PhotoShop Corel Draw Gaming


Download ppt "Hello world <?php print "hello world"; ?>. Variables A variable consists of a name that you can choose, preceded by a dollar ($) sign. Some legal variables."

Similar presentations


Ads by Google