jsj_PHP_笔记

  • 格式:pdf
  • 大小:351.77 KB
  • 文档页数:16

PHP ...... 1 1 ...... 1 2 (1)...... 2 1 ...... 2 2 (3)—— …… 3 1 …… 3 2 …… 4 3 — …… 4 ……5 ...... 5 PHP 6 1 ...... 6 1 die() exit() ...... 6 2 empty() ...... 7 3 iset() unset() (7)4 settype() ...... 8 5 is_bool()...... 8 2 ...... 9 3 ...... 10 1 time() ...... 10 2 mktime() ...... 10 3 date() mgdate() ...... 10 4 getdate() ...... 11 5 checkdate() ...... 12 6 (13)0 15PHP1PHP function 4 function ([1 2 3……]){ return } PHPPHP PHP n<?php function nRecursion($n){ $s = 1; for ($i=1;$i<=$n;$i++){ $s=$s*$i; } return $s; } var_dump(nRecursion(4)); // int(24) ?>2PHP function ([ 1 2 3……]); round round PHP1 15PHP float round(float $var[,int $precision])var precisionvar precision float <?php $floatNumber =725.386; echo " ".$floatNumber.""; $result1 = round($floatNumber); // 725 echo " ". $result1.""; $result2 = round($floatNumber,2); // 725.39 echo "".$result2.""; $result3 = round($floatNumber,-2);// 700 echo "".$result3; ?>PHPPHPreturnreturn1returnreturn <? php function multiplication($a,$b){ $result = $a * $b; return $result; } echo "3 * 10 =".multiplication(3,10); ?>2 15PHP2<?php function number(){ Return array(1,2,3); } list($one, $two,$three)=number(); // list echo "$one ".$one.""; echo "$two ".$two.""; echo "$three ".$three.""; ?>—— ————1PHP <? php function divisor($m,$n){ if($m%$n==0){ return $n; }else{ return divisor($n,$m%$n); } } $a = 12; $b = 8; $result = divisor($a,$b); echo $a." ".$b." ". $result; // 12 8 4 ?>3 15PHP2PHP C++ b a c <?php function printVar($a,$b=10,$c){ // $b echo "a = $a b = $b c = $c"; } $a = 1; $c = 3; echo printVar ($a,$c); ?> PHP NULL3 — —PHPPHP<?php function change ($number){ $number = $number +1; // $number 1 echo " \$number ".$number.""; // 11 } $number = 10; change ($number); // change() echo " \$number ".$number; //$number ?> &”4 15PHP <?php function change ($number){ $number = $number +1; echo " \$number ".$number.""; // 11 } $number = 10; chang(&$number); // chang() echo " \$number ".$nubmer; // $number 11 ?>PHP PHPglobal $GLOBALS[] & unset() require() include() <?php $price = 0; //function sale($price){ $price = 100; //$newPrice = $price*0.95; // 9.5 echo " ".$price.""; return $newPrice; // $newPrice } echo " ".sale ($price).""; echo " ".$price; ?>PHP $var() $variable() PHP5 15PHP $var <?php function caculate($length,$width){ $area = $length * $width; echo " ".$length.""; echo " ".$width.""; echo " ".$area.""; } $length = 10; $width = 5; $myFunction = "caculate"; $myFunction ($length,$width); ?> PHPPHPPHP Web1exit() empty()1 die() exit()die() exit() PHP die() exit() exit() void exit([string $status]) status status 0~254 0 exit() exit () <?php $var = "PHP "; echo $var; exit(0); // echo " "; // PHP ?>6 15PHP2 empty()empty() 0 0 truefalse false “0” 0 NULL FALSE array $var bool empty mixed $var var empty() <? php $var = "PHP "; if(empty($var)){ // $var echo "\$var 0"; }else{ echo "\$var \"".$var."\" ";; } $null = ""; if(empty($null)){ // $null echo "\$null 0"; }else{ echo "\$null \"". $null."\""; } $zero = 0; if(empty($zero)){ // $zero echo "\$zero 0"; }else{ echo "\$zero \"". $var."\""; } ?>3 iset() unset()isset() true false bool isset(mixed $var); varunset() true void unst(mixed $var) varisset() <?php $var1 = $variable; $var2 = null; if(isset($var1)){ echo "\$var1\$var2 "; }else{ echo "\$var1\$var2 ";7 15PHP } ?>4 settype()settype() true falsesettype() bool settype(mixed & $var,string $type) var typeboolean integer floatstring array object nullsettype() <?php $php = "PHP "; echo "\$php ".$php.""; settype($php,"integer"); echo "\$php ".$php; ?>5 is_bool()is_bool() truefalse bool is_bool(mixed $var) varis_bool()<?php $php = true; if(is_bool ($php)){ echo "\$php "; }else{echo "\$php "; } ?> is_bool () PHP is_”is_string()if_float ()8 15PHP2PHPPHP PHPmixed abs(mixed $number) float acos (float $arg) float cos(float $arg) float asin(float $arg) float sin(float $arg)float atan(float $arg) float atan2(float $y,float $x) float tan(float $arg)sting base_convert(string $number,int $frombase,int $tobase)number arg argarg arg argatan()arg number frombase tobasearg E base exp number val numberrand() minmax seed E arg 10 argnumberargint bindec(string $binary_string)string decbin(int $number) int hexdec(string $hex_string) int octdec(string $octal_string) string dechex(int $number) string decoct(int $number) float exp(float $arg) float pow(float $base,float $exp) int floor(float $number) double round(double $val[,int $precision]) int ceil(float $number) int getrandmax(void) int rand([int $min],[int $max]) void srand(int $seed)float log(float $arg) float log10(float $arg) mixed min(mixed $arg1,mixed$arg2,mixed $argn) mixed max(mixed$arg1,mixed $arg2,mixed $argn)string number_format(float $number,int $decimals,string $dec_point,string $thousands_sep)double pi(void) float sqrt(float $arg) <?php $float = 7.16;9 15PHP Echo "\$float ".$float." "; // $float 7.16 Echo " ".round($float).""; // 7 Echo " ".floor($float).""; // 7 Echo "".ceil($float).""; // 8 $int = 1234; Echo "\$int ".$int.""; // $int 1234 Echo " ".dechex($int).""; // 4d2 Echo " ".decoct($int).""; // 2322 Echo " ".decbin($int).""; // 10011010010 ?> PHP M_PI pi ()31 time()time 1970 1 1 time() UNIX int time(void) 1970 1 1 UNIX UNIX Windows UNIX2 mktime()mktime() UNIXmktime() date() Int mktime([int $hour[,int $minute [,int $second[,int $month[,int $day[,int $year]]]]]]) hour minute second monthday year3 date() mgdate()date() mgdate()date()10 15PHP mgdate() date()mgdate() String date (string $format [,$timestamp]) String gmdate(string $format [,$timestamp]) FormatTimestamp UNIXa A d D F h H g G i j l L m n M s S tU w y Y z am pm AM PM01 313 Fri January 12 01 1224 00 24121 1224 024 0 591 31Friday0 101 12 1 12 300 59 th nd 28310 6 10 2010 0 365 date()<?php echo "date() ".date("Y n j H:i:sa").""; echo "gmdate() ".gmdate(Y n j H:i:sa).""; ?>4 getdate()getdate()getdate() array getdate ([int $timestamp]) timestamp UNIX11 15PHP getdate() timestampgetdate()seconds minutes hours mday wday mon year yday weekday month 00 59 0 590 231 310 6112 4 2010 0365 Friday January UNIX time() date() getdate()<?php $today = getdate(); print_r ($tody); ?> Array ( [seconds] => 5 [minutes] => 18 [hours] => 9 [mday] => 16 [wday] => 2 [mon] => 3 [year] => 2010[yday] => 74 [weekday] => Tuesday [month] => March [0] => 1268702285 )5 checkdate()checkdate()bool checkdate(int $mounth,int $day,int $year) mouth day year checkdate() true false0 32767 1 12checkdate() <? php $month = 5; $day = 33; $year = 2010;12 15PHP $boolean = checkdate($month, $day,$year); if($boolean==true){ echo " "; }else{ echo " "; } ?>61) include() include_once() include() include() const.php”include.php” const.php <?php $OK = 1; $ERROR = 0; ?> include.php <?php include"const.php"; echo "OK ".$OK." "; echo "ERROR ".$ERROR; ?> include_once() include() include_once()include_once() 2) require() require_once() require() include() require() include()require_once() include_once()Require_once() 3) eval() eval() include() eval() PHP include() eval() exit();” PHP<?php13 15PHP $string = "exit()"; eval ($str); echo " "; ?> echoeval() eval () eval() eval()14 15。