mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-05-21 22:00:59 +00:00
Update function declarations to adhere to PSR-2 standards
This commit is contained in:
parent
fa03534bb8
commit
91da073b45
@ -318,7 +318,7 @@ for ($i = 0; $i < 5; $i++) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Define a function with "function":
|
// Define a function with "function":
|
||||||
function my_function() {
|
function my_function () {
|
||||||
return 'Hello';
|
return 'Hello';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ echo my_function(); // => "Hello"
|
|||||||
// A valid function name starts with a letter or underscore, followed by any
|
// A valid function name starts with a letter or underscore, followed by any
|
||||||
// number of letters, numbers, or underscores.
|
// number of letters, numbers, or underscores.
|
||||||
|
|
||||||
function add($x, $y = 1) { // $y is optional, and defaults to 2
|
function add ($x, $y = 1) { // $y is optional and defaults to 1
|
||||||
$result = $x + $y;
|
$result = $x + $y;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@ -339,7 +339,7 @@ echo add(4, 2); // => 6
|
|||||||
// print $result; // Gives a warning.
|
// print $result; // Gives a warning.
|
||||||
|
|
||||||
// Since PHP 5.3 you can declare anonymous functions;
|
// Since PHP 5.3 you can declare anonymous functions;
|
||||||
$inc = function($x){
|
$inc = function ($x) {
|
||||||
return $x + 1;
|
return $x + 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user