Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PHP 101: flow control
Search
LucienLee
June 27, 2013
Programming
0
320
PHP 101: flow control
Fundamental PHP & Web Development
LucienLee
June 27, 2013
Tweet
Share
More Decks by LucienLee
See All by LucienLee
SASS & Compass 101
lucienlee
1
290
Use PaaS service to host your web - with pagodabox
lucienlee
0
72
final album
lucienlee
0
65
Simple Album
lucienlee
0
79
Accessing MySQL from PHP
lucienlee
1
350
DataBase and MySQL
lucienlee
1
230
PHP 101+1:function & form
lucienlee
1
270
Start to Build your Web
lucienlee
1
420
既然如此,那我們來hack資本世界吧!
lucienlee
0
150
Other Decks in Programming
See All in Programming
DDDはなぜ難しいのか / 良いコードの定義と設計能力の壁
pospome
24
6.7k
15分間でふんわり理解するDocker @ Matsuriba MAX
ukwhatn
PRO
1
330
MySQL のインデックスの種類をおさらいしよう! / overviewing indexes in MySQL
okashoi
0
170
オブジェクト指向は必要なのか / Is object-oriented needed?
kishida
27
18k
LPIXEL×CADDi_kaerururu
kaerururu
3
300
AppDeveloperCon 2024 EU: Building polyglot developer experiences in 2024
salaboy
0
370
WebComponentsで フレームワークを1ページに共存させる
webuilder240
0
150
PHP8の機能を使って堅牢にコードを書く
fendo181
6
2.6k
オブジェクト指向コードレビューの新しいアプローチ
akkie76
3
1.1k
フロントエンドパフォーマンス 入門
shouta2
7
1.5k
PHP 8.3で追加されたjson_validate()を徹底的に深掘りしてみよう
mashirou1234
1
720
RubyVM を PHP で実装する 〜Hello World を出力するまで〜
memory1994
PRO
1
490
Featured
See All Featured
Pencils Down: Stop Designing & Start Developing
hursman
115
11k
How To Stay Up To Date on Web Technology
chriscoyier
781
250k
Design by the Numbers
sachag
274
18k
The Power of CSS Pseudo Elements
geoffreycrofte
58
4.9k
Mobile First: as difficult as doing things right
swwweet
215
8.5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
18
1.7k
YesSQL, Process and Tooling at Scale
rocio
160
13k
Atom: Resistance is Futile
akmur
258
25k
How GitHub (no longer) Works
holman
301
140k
Build The Right Thing And Hit Your Dates
maggiecrowley
23
1.9k
A better future with KSS
kneath
230
16k
Designing for humans not robots
tammielis
247
25k
Transcript
PHP 101: flow control Fundamental PHP & Web Development lecturer
: Lucien Lee 李柏緯 Lecture 2
? What is flow control 2
3 eat SLEEP DRINK PUPU Straight Life
4 Real Life is complicated
5 Based Condition, Decide what to do.
IF 6 if something happen, what should we do?
IF •If my dog is gone, I call its name.
7
IF if($dog == ‘gone’){ echo “Where are you, Lucy!”; }
8
IF..ELSE.. 9 more statement to if not
ELSE •If my dog is gone, I call its name;
else I play with it. 10
ELSE if($dog == ‘gone’){ echo “Where are you, Lucy!”; }else{
$myState = “play”; } 11
ELSEIF 12 Give MOre condition and RESPonse
ESLEIF •If my dog is gone, I call its name;
else if my dog is eating, I go to eat. 13
ELSEIF if($dog == ‘gone’){ echo “Where are you, Lucy!”; }elseif($dog
== ‘eating’){ $myState = “go to eat”; } 14
? LOOP 15
16 eat SLEEP DRINK PUPU But you get older
17 for Do one by one, until satisfy condition.
18 for •Count from 1 to 10.
for for($i=1; $i<=10; $i++){ echo $i.’<br>’; } 19
20 while Do again by again, until satisfy condition.
21 while •Count from 1 to 10.
while $i=1 while($i<=10){ echo $i.’<br>’; i++; } 22
23 foreach traverse array one by one
foreach $price = array(“apple”=>100, ”orange”=>150, “banana”=>200); foreach($price as $key =>
$value){ echo “水果: ”. $key.”/價錢: ”. $value; } 24
ARRAY Part 2 25
? Multi-Array 26
ARRAY •a collection of data items. •key map to value.
•Like many box put together. 27 Apple 100 Orange 150 Banana 200
28 0 1 2 0 A B C 1 D
E F 2 G H I Multi-Case
Multi-Array 29 $array[0][‘cool’] = ‘awesome’; $array[1] = “XD”; $array[0][1][‘yeah’] =
“yo”; //wrong case $array[0]=100;
key-value 30 red white yellow purple flower rose lily sumflower
fruit apple pear banana grape
Multi-Array 31 $set=array( ‘flower’=>array(‘red’=>‘rose’,‘whit e’=>‘lily’,‘yellow’=>‘sunflower’), ‘fruit’=>array(‘red’=>‘apple’, ‘white’=>‘pear’,‘yellow’=>‘banana’, ‘purple’=>‘grape’) );
+ union two array 32
two array plus $item1 = array(‘rose’,‘lily’); $item2 = array(‘apple’,‘banana’,‘grape’); $items
= $item1 + $item2; //$items = array(‘rose’,‘lily’, ‘grape’); 33
array_push() add a new data to array 34
array_pop() remove last data from array 35
Live Coding 36
HomeWork 37 • make key-value array to save student grade.
• All grade * 1.4, if modified grade over 100, modify in another way:original value + (100 - original value)*0.1 • change array as name map to array save grade and pass or not. a b c d e f 30 40 90 60 55 80