1 Pertemuan 14 PHP: Conditions-loops-functions-Array Last Updated: 23 rd May 2011 By M. Arief
2 Objectives ► To learn to use logical test operators to create compound conditional test statements ► To learn to use conditional test statements to compare numerical and string data values ► To learn to use looping statements to repeat other statements ► To learn to use several PHP functions useful for Web application development ► To learn to write and use your own functions
3 IF-Statements if (some test) { // code here } else if (some other test) { // code here } else { // if neither test met, do this }
4 Comparison Operator == Equals > Greater than < Less than >= Greater or equal to <= Less or equal to !=, <> Not equal
5 Logical Operator ! NOT !$b Returns true if $b is false && AND $a && $b Returns true if both $a and $b are true || OR $a || $b Returns true if either $a or $b or both are true and AND $a and $b Same as && or OR $a or $b Same as ||
6 SWITCH-Conditionals
7 SWITCH-Conditionals
8 PHP Loops ► Loops provide a mechanism for executing a section of code repeatedly. ► PHP supports four kinds of loops: for, while, do-while and foreach for, while, do-while and foreach
9 FOR-loop
10 WHILE-loop
11 DO-WHILE-loop
12 FOREACH-Loop ► Used extensively to grab and manipulate values from arrays. ► We'll cover this control structure in depth next session with Arrays.
13 PHP Function
14 PHP Function date(), time(), empty
15 PHP Function
16 PHP Function: Return Value
17 PHP Function: Return Value
18 Creating an Array
19 Creating an Array
20 Creating an Array
21 Creating an Array
22 View Array Structure
23 View More Array Details
24 Add Items to an Array
25 Be Careful
26 Delete an Array Element
27 Merge and Count
28 FOREACH and Array
29 FOREACH and Array
30 Implode: from Array to String
31 Explode: from String to Array
32 Array Search
33 Multidimensional Array
34 Multidimensional Array
35 Pertemuan 14 Session Last Updated: 23 rd May 2010 By M. Arief
36 Objectives ► To understand sessions and basic session functionality ► To learn how to use sessions to build multiple page sites with state preservation ► To learn how to use browser cookies to track data about the user ► To learn how to use PHP session handling functions to track various data ► To learn how to declare and use classes
37 HTTP Limitations
38 Chaining Variables in URL’s
39 The Session Solution
40 Sessions
41 How PHP Sessions Work
42 session_start()
43 Common Error
44 Setting and Accessing Session Value
45 Deleting Session Value
46 Contoh Session1.php <? // start the session session_start(); print "Registrasi Sesi Selesai. "; echo "ID sesi anda adalah ". session_id()." "; $data = "arief"; $_SESSION['name'] = $data; echo " Session Value anda adalah ". $_SESSION['name']. " "; ?> Sessio2.php <? session_start(); echo "ID sesi anda pada halaman ke-2 adalah ". session_id()." "; echo " Session Value anda pada halaman ke-2 adalah ". $_SESSION['name']. " "; ?>