120 likes | 261 Views
PHP: User-Defined and Built-in Functions. Speaker: Chin-Chang Chang Date:2007.3.21. User-Defined Functions. function function_name (parameters) { entity; } function_name();. demo. hello(); function hello() { echo "Hello, world!"; }
E N D
PHP: User-Defined and Built-in Functions Speaker: Chin-Chang Chang Date:2007.3.21
User-Defined Functions • function function_name (parameters){ entity;} • function_name();
demo • hello(); • function hello(){ echo "Hello, world!";} • http://stu.csie.ncnu.edu.tw/~beautidays.99/demo6.phps
$GLOBALS (1/2) • $temp = 6;clear();echo $temp; • function clear(){ $temp = 0;} • http://stu.csie.ncnu.edu.tw/~beautidays.99/demo7.phps
$GLOBALS (2/2) • $temp = 6;clear();echo $temp; • function clear(){ $GLOBALS[ 'temp' ] = 0;} • http://stu.csie.ncnu.edu.tw/~beautidays.99/demo8.phps
demo • hi(Joe, 18); • hi(May, 23); • function hi($x, $y){echo $x . " is " . $y . " years old.<br>";} • http://stu.csie.ncnu.edu.tw/~beautidays.99/demo9.phps
rand(); • rand($min, $max); • $i = rand();echo $i . "<br>";$j = rand(1,1000);echo $j; • http://stu.csie.ncnu.edu.tw/~beautidays.99/demo10.phps
getdate(); • getdate(); • Return an array • $today=getdate();echo $today[year]; echo $today[mon];echo $today[mday]; • http://stu.csie.ncnu.edu.tw/~beautidays.99/date.phps
strlen(); • strlen($string); • $s=“Good Afternoon”;$len=strlen($s);echo $s;echo “The length is ”.$len; • http://stu.csie.ncnu.edu.tw/~beautidays.99/strlength.phps
Reference • http://www.php.net/docs.php • http://member.ettoday.com/book/
HW3 • http://solomon.ipv6.club.tw/Course/Database.952/hw3.html • Two URLs: one for source code and one for execution.