Php function, php function manual. Php functions: the real power of php functions comes from its functions. PHP provides over 1000 built-in functions. In this chapter, we will explain how to create your own php functions and the php function manual.
The real power of PHP comes from its functions.
PHP provides over 1000 built-in functions.
In this chapter, we will explain how to create your own functions.
To execute the script during page loading, you can put it in the function.
A function is executed by calling a function.
You can call a function anywhere on the page.
Create a PHP function
A function is executed by calling a function.
Syntax
Function functionName () {code to be executed ;}
PHP function principles:
- The function name should prompt its function
- Function names start with letters or underscores (cannot begin with numbers)
Instance
A simple function can output my name when it is called:
Output:
My name is Kai Jim Refsnes
PHP functions-add parameters
To add more functions to a function, we can add parameters. Parameters are similar to variables.
The parameter is specified in brackets after the function name.
Instance 1
The following instances output different names, but the last names are the same:
";}echo "My name is ";writeName("Kai Jim");echo "My sister's name is ";writeName("Hege");echo "My brother's name is ";writeName("Stale");?>
Output:
My name is Kai Jim Refsnes.My sister's name is Hege Refsnes.My brother's name is Stale Refsnes.
Instance 2
The following functions have two parameters:
";}echo "My name is ";writeName("Kai Jim",".");echo "My sister's name is ";writeName("Hege","!");echo "My brother's name is ";writeName("Ståle","?");?>
PHP function-return value
If you want the function to return a value, use the return statement.
Instance
Output:
1 + 16 = 17
Address: http://www.manongjc.com/php/php_functions.html
Related reading:
Php instance to get the checkbox value of all the check boxes of the form
Php checks whether the check box checkbox is selected
How does php obtain the checkbox value?
Php complete form submission example
Php form submission for detailed analysis
The real power of PHP comes from its functions. PHP provides over 1000 built-in functions. In this chapter, we will explain how to create your own...