PHP functions
The real power of PHP comes from its functions
Functions are executed by calling functions and can be called anywhere on the page
PHP Function Guidelines:
Function name begins with a letter or underscore (cannot start with a number)
The name of the function should indicate its function
Four elements:
return type, function name, argument list, function body
(Weak types do not require return type)
Grammar:
1. Basic functions:
function functionname ()
{
echo "Hello"
}
FunctionName ();
2. function with return value to add return
3. parameter function definition to give a formal parameter, output with an actual parameter
4. Functions of variable parameters
function sum ()
{
$attr = Func_get_args (); (get: Get; args: Parameter)
$n = Func_get_args;
$sum = 0
(For Loop)
}
Array:
Arrays can store multiple values in a single variable
You can store any type of data in an array
The array is contiguous and the length is fixed
1. $attr = Array (for each);
2. $attr 1 = [1,2,3,4,];
3. (assigned value) $attr 3[0] = "Nihao"
$attr 3[1] = "HI"
Gets the length of the array: (count)
echo count ();
Array type:
Indexed array
$attr = Array (+/-);
Var_dump ($ATTR);
Associative arrays
$attr 1 = Array ("One" =>1, "=>2")
Iterating through an array
For loop traversal cannot traverse associative array
foreach loops (indexes, associations can traverse)
foreach (array as variable)
{
The echo variable. <br> ";
}
each ()
List ($1,$2,$3) = $attr assigns the elements inside the right array to the variables on the left
while (list (variable) = each (array))
{
echo "{variable} {variable}<br>"
}
Using pointers:
Current ()
Get the current pointer position content data
Key ()
Gets the index value of the current pointer position
Prev ()
Returns the internal pointer of the array back to a
Next ()
Moves the inner pointer in the array forward one
End ()
Point the inner pointer of an array to the last cell
Reset ()
Point the inner pointer of an array to the first cell
PHP functions, arrays