Presentation is loading. Please wait.

Presentation is loading. Please wait.

>> Fundamental Concepts in PHP

Similar presentations


Presentation on theme: ">> Fundamental Concepts in PHP"— Presentation transcript:

1 >> Fundamental Concepts in PHP

2 Variables Variable In PHP An entity that can hold a value
Variable Names start with “$” sign Assignment operator is the same “=“ Must begin with a letter or an underscore (_) Must contain only alpha-numeric values and underscore No Spaces Case-sensitive NAMING RULES TRY NOW Create a variable called name and add your name as the value

3 Strings Strings PHP Like JavaScript, PHP also uses strings
String concatenation is done using “.” (unlike JavaScript where we use the “+” operator) Provides a number of string processing functions echo $txt1 . " " . $txt2;

4 Greater than or equal to
Operators Inc / Dec Operator Name ++ x Pre-increment x ++ Post-increment -- x Pre-decrement x -- Post-decrement Comparison Arithmetic Operator Name x + y Addition x - y Subtraction x * y Multiplication x / y Division x % y Modulus Operator Name x == y Equal x === y Identical x != y Not equal x <> y x !== y Not identical x > y Greater than x < y Less than x >= y Greater than or equal to x <= y Less than or equal to Logical Operator Name x and y And x or y Or x xor y Xor x && y x || y ! x Not

5 Conditional Conditionals PHP
Provides a way to have certain commands executed only if some condition is met PHP If statement If…..Else statement Switch statement

6 IF Conditional If statement TRY NOW SYNTAX Create a variable password
{ } SYNTAX Create a variable password Initialize it with a value Now check if the password is equal to If true, Echo “Welcome” TRY NOW

7 IF-Else Conditional If-Else statement TRY NOW SYNTAX
if(cond) { } else SYNTAX Now add an else statement to the previous statement If the password is not correct then echo “You are in the wrong neighborhood” TRY NOW

8 Complex Conditional If-Else statement with Complex Conditional TRY NOW
if(cond) { } else SYNTAX Now add another variable called username and initialize to a value called “labuser”. Now change the if condition to check if username is equal to “labuser” and password is equal to TRY NOW

9 Switch Conditional Switch statement TRY NOW SYNTAX
switch (n) { case label1:    code to be executed if n=label1;    break; ……… default: } SYNTAX TRY NOW Create and initialize a variable called item. Then switch the variable If item is eggs then echo “SAR 3.65” If item is milk then echo “SAR 5.00” Else echo out “SAR 0.00”

10 Loops Looping Provides a way to have certain block of commands to be executed again and again for certain number of times PHP While Loop Do….While Loop For Loop ForEach

11 While Loop While statement TRY NOW SYNTAX
while(cond) { } SYNTAX Use the while loop to repeat some text 10 times TRY NOW

12 Do-While Loop Do-While statement At least runs the loop once TRY NOW
{ } while(cond); SYNTAX At least runs the loop once Repeat the previous exercise using do-while loops instead. TRY NOW

13 For Loop For Loop TRY NOW HINT: SYNTAX Create an array
for(init; cond; increment) { } SYNTAX Create an array Display its elements using the for-loop TRY NOW HINT: Use count() to get the length of the array

14 Functions in PHP Functions Group Block of Code Reusable Code TRY NOW
function name(paramters) { return value; } SYNTAX Separate by comma Use “$” sign Create a function add() which takes two parameters and returns the result which is the sum of the two numbers. TRY NOW

15 Important String Functions
Length: strlen(‘string’); Substring: mb_substr(‘string’, start, length); Break string into array: explode(break-char, ‘string’); Join: implode(array-name, join-char); Reverse: strrev(‘string’); To Upper Case: strtoupper(‘string’); To Lower Case: strtolower(‘STRING’); Times Occurance: substr_count(‘My My’,’sub-string’);

16 Web-Based Systems - Misbhauddin
Next on PHP Integrating PHP with HTML Reusing PHP Files Web-Based Systems - Misbhauddin

17 Web-based Systems | Misbhauddin
Mini-PHP Project Mini Course Project Build an e-commerce website “Buy 4m Me” Listing all items you want to sell through the online store Customers can view and select the items Customers can add them to their cart Customer can checkout and make payment Confirmation s Web-based Systems | Misbhauddin


Download ppt ">> Fundamental Concepts in PHP"

Similar presentations


Ads by Google