Page 197 - CITS - Computer Software Application -TT
P. 197
COMPUTER SOFTWARE APPLICATION - CITS
In this example, the `calculateSum` function accepts any number of arguments using the `...$numbers` syntax. It
then calculates the sum of all provided numbers. You can call this function with different numbers of arguments,
and it will work accordingly.
This flexibility is beneficial when you need to create functions that can handle various scenarios without explicitly
defining the number of parameters.
PHP Functions - Returning values:
To let a function return a value, use the return statement:
Example:
PHP Built-in Functions
PHP has over 1000 built-in functions that can be called directly, from within a script, to perform a specific task.
Built-in functions in PHP are pre-defined functions that come with the language. These functions are readily
available for use and cover a wide range of functionalities, from string manipulation to mathematical operations.
Here’s a more in-depth look:
Common PHP Functions:
Explore commonly used functions like `strlen`, `str`_`replace`, `count`, etc.
Example:
PHP User Defined Functions
Besides the built-in PHP functions, it is possible to create your own functions.
• A function is a block of statements that can be used repeatedly in a program.
• A function will not execute automatically when a page loads.
• A function will be executed by a call to the function.
184
CITS : IT&ITES - Computer Software Application - Lesson 47 - 62