November 21, 2016 —John Koster
value($value)
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, 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.
Using value
with an instance of Closure
:
1<?php2 3$value = value(function()4{5 return 42;6});
In the above example, $value
would contain the integer 42
, because it was returned from the function.
The following example does not use an instance of Closure
:
1<?php2 3$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.