| Function | A function is a special piece of code that you can call to do something complicated. A function has a name, it is passed one or more parameters and it returns a result. |
| Making a Function | Before you can call a function, you must make it, like this:
function make_bold($s) {
return "<b>" . $s . "</b>"; // return passed the result back
}
|
| Calling a Function | Once the function is made, you can call it:
$bold_string = make_bold($string); echo make_bold($string); |
| Built-in Functions | There are many built-in functions for manipulating strings and arrays, dates and time,
math, and many other things. Here are a few examples:
$array = array(1,2,3); if (count($a) > 0) echo "array is not empty"; if (strcmp($answer, "yes") == 0) echo "answer was yes"; $random = rand(0,10); |