April 15, 2018 —John Koster
The value
function will return the default value of the supplied $value
. Although this sounds redundant, if the supplied $value
is an instance of the Closure
class (an anonymous function), the function will be executed and the value will be returned. If the $value
is not an instance of Closure
, the value is simply returned.
The signature of the value
function is:
1function value(2 $value3);
Using value
with an instance of Closure
:
1$value = value(function()2{3 return 42;4});
In the above example, $value
would contain the integer 42
, because it was returned from the supplied function.
The following example does not use an instance of Closure
:
1$value = value(42);
Again, $value
would contain the integer 42
.
∎
The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.