130 likes | 358 Views
Introduction to PHP. Data type Operators Statements. Data Type. Integer 4 bytes 1,2, 56, -12 Float 1.23, 3000.45 String “11AA”, “rrrr” Boolean ?? 0, 0.0, “”: false Others: true. Datatype. integer double string array object class unknown type. Variables. Case-sensitive
E N D
Introduction to PHP Data type Operators Statements
Data Type • Integer • 4 bytes • 1,2, 56, -12 • Float • 1.23, 3000.45 • String • “11AA”, “rrrr” • Boolean ?? • 0, 0.0, “”: false • Others: true
Datatype • integer • double • string • array • object • class • unknown type
Variables • Case-sensitive • $VariableName • $i, $moon, • Build-in function is not case-sensitive • echo() ?? ECHO() • Declaration • $num=10; • $num=10.0 • $num=“OOOO” • Ex: $k=10; $ks=“112HHHH”; • $addv=$k+$ks; ?? • $c=$a+$b;
Constant • Ex: • PI=3.14; • Syntax • Define(“PI”,3.14) • PI=39.34; • PI=$a+$b;
Build-in Functions • Gettype() • $i=30; • Echo(Gettype($i)) ?? • Settype() • $a=7.8; • Settype($a, “integer”) • …
Struct • Protein ?? • ID • Name • AtomNum • Type • $protein->id • $protein->name • $protein->atomnum • $protein->type
Operators • Calculation operators • +,-,*,/ • ++,-- • $a=10; $a++; /* a=? $a=$a+1;*/ • $a=10; $b=$a++; /* a=? , b=? */ • $a=10; $b=++$a; /* a=? , b=? */ • Boolean • >=,<=,!=,>,< • && (and) , || (or), • $I=10; • If (9=$I) echo “11111”; • String • . • $aa=“AAA” . “CCCC”; • @
Statements-1 • if ..then .. Else if ( $SNum > $ENum) $R= ">"; else if ( $SNum < $ENum) $R= "<"; else $R="=="; echo("$SNum $R $ENum");
Statements-2 • Switch <? $OperType = “a”; • Switch { Case.. } switch ($OperType) { case "a": $a = $SNum + $ENum; echo("$SNum + $ENum = " . $a ); case "s": $a= $SNum-$ENum; echo("$SNum - $ENum = " . $a); break; } ?>
Statements-3 • Loop (sum 1 to 100) • While { … } $Sum=0; $i=0; while ($Snum < $ENum) { // ?? $sum=$sum+$i; // ?? $i++; } // minimum executing time is 0 • Do {… } while <<see test1>> $Sum=0; $i=$Snum; do { $Sum=$Sum+$i; $i++; } while ($i<= $Enum); //minimum executing time is 1
Statements-4 • For ( ; ; ) { …} $Sum=0; $k=0; for ($i=$SNum;$i<=$ENum;$i++,$k++) $Sum=$Sum+$i;