September 2024
Intermediate to advanced
743 pages
27h 48m
English
Almost every programming language contains functions, and PHP is no exception, to generate recurring parts of code.
A function must be introduced via the function keyword, followed by the parentheses, in which the parameters can be entered. After that, the statements to be executed are inside the curly brackets. Listing 15.28 shows an example. Embedded within the function is the while example from Section 15.4.2. The function is called with its function name followed by two parentheses.
<?phpfunction printNumbersFrom1To10() { $i = 1; while ( $i <= 10 ) { echo $i ++; }}printNumbersFrom1To10();
Listing 15.28 Defining and Executing a Function
Read now
Unlock full access