Posted on



PHP Functions

PHP Functions allow you to combine several statements of code into a ‘function’. These functions can then be called by their given name, and all of the code contained will run and return the results. This will drastically help you clean up code and use less repetitive code.

1. Introducing Functions

The very basics of how custom functions in PHP work is what you will learn here. We will leave understanding how a function is structured as well as how to pass in arguments and set defaults for those arguments.

6:52
Introducing Functions
6:11
PHP Function Arguments
6:58
PHP Function Default Arguments

2. Function Returns and More

In most cases we will want to do more than just echo a value inside of our functions, in order to do that we will need to have the function ‘return’ a value. This way we are able to store data from a function call to any type of value variable. We will go into this and more functions types in this stage.

7:51
Returning Values
5:25
PHP Variable Functions
4:14
PHP Closures

3. PHP Internal Functions

PHP has tons of built in functions to make your life as a PHP developer so much better. We will learn how to find these internal functions, read the docs, and use them!

2:26
PHP Built-Ins and Documentation
8:59
PHP String Functions
8:11
PHP Array Functions
0:42
PHP Functions Next Steps

Nguồn: https://milchreis.org/

Xem thêm bài viết khác: https://milchreis.org/cong-nghe/

9 Replies to “PHP Closures”

  1. Why cant you just pass it through as a argument? this code here runs just like yours.

    $name = 'frank';

    $greet = function($name) {

    echo "Hello, $name !";

    };

    $greet($name);

    Outputing:
    Hello, frank !

    so why shouldnt we use this?

  2. its' not true that anonymous function assings it's output to variable $greet in statement:
    $greet = function() {
    echo 'Hello there';
    };
    it's as if the variable $greet contains the function it self, not it's output.
    consider code:
    $greet = function() {
    return 'Hello there';
    }
    echo $greet; // error (php 7)

Leave a Reply

Your email address will not be published. Required fields are marked *