O
O
Outoverlay2015-10-16 13:37:31
PHP
Outoverlay, 2015-10-16 13:37:31

How to create a callback in php?

how to create a function in php like this:
name_func(function(){
//code
});
I know how to do this in js, but is the implementation in php interesting?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2015-10-16
@Outoverlay

function foo(callable $bar)
{
    $bar();
}

foo(function () {
    echo 5;
});

M
Maxim, 2015-10-16
@maxpointn2point

Documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question