Attention:
1, php function parameters, when using the default parameters, any default parameters must be placed on the right side of any non-default parameters, otherwise the function will not work as expected.
2. PHP cannot return multiple values, but can achieve the same effect by returning an array
function Getarr () {
return Array (+/-);
}
List ($a, $b, $c) =getarr ();
3, return a reference from the function, you must use the operator when declaring and assigning return values to a variable &
Global $arr;
$arr =array (3);
Function & Return_reference () {
Global $arr;
Print_r ($arr);
return $arr;
}
$newref =& return_reference ();
$newref [0]=4;
$newref =& return_reference ();
4. Anonymous function
Class cart{
Const price_butter=1.00;
Const price_milk=3.00;
Const price_egg=6.95;
Protected $products =array ();
Public Function getquantity ($product) {
return isset ($this->products[$product])? $this->products[$product]:false;
}
Public Function Gettotal ($tax) {
$total =0.00;
$callback =function ($quantity, $product) use ($tax,& $total) {
$pricePerItem =constant (__class__. "::P rice_". Strtoupper ($product));
$total + = ($pricePerItem * $quantity) * ($tax +1.0);
}
Array_walk ( $this->products, $callback);
Return round ($total, 2);
}
}
$mycart =new Cart;
$mycart->add (' Butter ', 1);
$mycart->add (' Milk ', 3);
$mycart->add (' eggs ', 6);
echo $mycart->gettotal (0.05);
The above introduces the use of PHP function note points, including the use of attention, PHP content, I hope that the PHP tutorial interested in a friend helpful.