domifrosle domifrosle - 8 months ago 23
PHP Question

Getting the return value from a function

Say I got some function that run some code and then

something, like this:

function something()
//some code
return $some[$whatever];

So, if I want to extract the data I generated in the function - the new value for
, how should I do it? for example this won't do anything:

echo ($some);

Or what am I missing here, please


Since your Function returns a value, You may need to catch & store it inside a variable and then echo the variable if it is a String or do some casting to that effect. Here's an example:

    function something(){
        //some code
        $whatever  = 3;
        $some      = ["Peace", "Amongst", "All", "Humanity"];
        return $some[$whatever];

    $var = something();

    var_dump($var); //<== DUMPS :: "Humanity"
    echo $var;      //<== ECHOES:: "Humanity"

Test it out here.

Cheers and Good Luck....