A
A
Archakov Dennis2015-11-08 18:53:26
PHP
Archakov Dennis, 2015-11-08 18:53:26

How to execute a custom function from the function itself?

How to call a function in PHP header and pass parameters to it?
For example:myFunc('helloworld',function(){ echo "test" });

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin B., 2015-11-08
@archakov06

We check whether the variable is a value or a function, if it is a function, then we call it

myFunc('helloworld', function(){ 
    echo "test" 
});

function myFunc($key, $object){
    return is_callable($object) ? call_user_func($object):$object;
}

P
profesor08, 2015-11-08
@profesor08

For example like this:

function myFunc($text, $func)
{
    $func($text);
}

myFunc("blabla", function($param) { echo $param;});

S
Stalker_RED, 2015-11-08
@Stalker_RED

$hello = function($name = '') {
    return "Hello $name";
};
echo $hello('John'); // Hello John

sandbox.onlinephpfunctions.com/code/8c2e26eda94c61...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question