ICT 5 Web Development - Chapter : Functions Basic PHP Functions, Write your own functions, Using External Script Files, The abs Functionabs, The sqrt Function, The round Function, The datedate Function, Function definition. | Vietnam and Japan Joint ICT HRD Program Objectives To learn to use several PHP functions useful for Web application d f lf b l development l To learn to write and use your own functions ITC 5 – Web Programming Chapter 3-2. Functions Nguyen Thi Thu Trang trangntt@ 2 Content Content 1. Basic PHP Functions 2. Write your own functions 3. Using External Script Files 1. Basic PHP Functions 2. Write your own functions 3. Using External Script Files 3 4 1 1. Basic PHP Functions Numberic PHP Functions We previously discussed functions such as strlen(), trim(), strtolower(), strtoupper(), and substr(). In this section we examine several other useful functions including – Some basic numeric PHP functions ., ., the absolute value[abs()], square root [sqrt()], round [round()], integer checker[is_numeric()], and random number generation [rand()] functions. – The print() function Absolute value Square root, Round, Integer checker Random number generation We will cover in more detail – The date() function We will discuss using the date() function to determine date and time information. 5 6 . The abs() Function . The sqrt() Function The absolute value function takes a single numerical argument and returns its absolute value. For example, the following The square root function takes a single q g numerical argument and returns its square root. For example, the following $x=sqrt(25); $y=sqrt(24); print "x=$x y=$y"; $x=abs($x=abs(-5); $y=abs(42); print "x=$x y=$y"; Will output Will output – x=5 y= – x=5 y=42 7 8 2 . The round() Function . The round() Function The round function takes a single numerical g argument and returns the number rounded up or down to the nearest integer. For example, the following You can include 2nd argument to define the number of digits after the decimal point to round to. For example, $x=round($x=round(); $y=round(); print "x=$x .