Section III PHP syntax
1. Debug Configuration
Configure PHP Interpreter
Under Windows platform: set PHP home:c:\xampp\php
Under MAC platform: set PHP Home:/opt/lampp/bin
2.PHP identifiers
<?PHPEcho' Hello ';//Change of Reputation$a=10;Echo $a;Echo' <br> ';//The const PHP5 is the syntax of theConstThe_value = 100;EchoThe_value;//constant FameDefine(' The_value2 ', 200);Echothe_value2;?>
3 functions
<?PHP//Method Onefunctiontracehellophp () {Echo' Hello php<br> '; Echo' Hello word<br> ';}//Method Two$func= ' tracehellophp ';$func();//Method ThreefunctionSayhelloto ($name){ Echo' Hello '.$name.‘ <br> ';} Sayhelloto (' Xiaoming ');//method FourfunctionTracenum ($a,$b){ Echo' A = '.$a. ', B = '.$b. ' <br> '; Echo"A=$a, b=$b<br> ";} Tracenum (2,3);//Method FivefunctionAdd$a,$b){ return $a+$b;}EchoAdd (10,2);?>
View Code
4 Process Control
<?PHPfunctionGetlevel ($score){ if($score>90){ returnExcellent; }Else if($score>80){ returnGood; }Else if($score>70){ returnGood; }Else if($score>60){ returnCan; }Else{ returnPoor; }}functionGetLevel2 ($score){ Switch($score/10) { Case10: Case9:returnExcellent; Case8:returnGood; Case7:returnGood; Case6:returnCan; default:returnPoor; }}EchoGetlevel (90);?>
View Code
5 Cycles
<?PHP for($i= 0;$i<100;$i++){ Echo' Hello '.$i.‘ <br> '; if($i==20) { Break; }}$i= 0; while($i<100){ Echo' Hello '.$i.‘ <br> '; $i++;}$i=0; Do{ Echo' Hello '.$i.‘ <br> '; $i++;} while($i<100)?>
View Code
6 Logical operations
<? PHP function traceNum3 () { for($i$i<=100; $i++ ) {if($i$i%3==0) {echo $i. ' <br> '; } }? >
View Code
Section III PHP syntax