The
value
function returns the value it is given. However, if you pass a closure to the function, the closure will be executed and its returned value will be returned:<?php $result = value(true);
$result = value(function () {
return false;
});
<?php public function dispatchIf($boolean)
{
return value($boolean) ? $this->dispatch() : null;
}
<?php public function dispatchUnless($boolean)
{
return ! value($boolean) ? $this->dispatch() : null;
}
<?php if (is_null($value)) {
$this->event(new CacheMissed($this->getName(), $key));
$value = value($default);
} else {
$this->event(new CacheHit($this->getName(), $key, $value));
}
<?php if (is_null($value)) {
$this->event(new CacheMissed($this->getName(), $key));
return (isset($keys[$key]) && ! array_is_list($keys)) ? value($keys[$key]) : null;
}
<?php $value = $callback();
$this->put($key, $value, value($ttl, $value));
return $value;
}
<?php {
if (is_null($callback)) {
if (empty($array)) {
return value($default);
}
foreach ($array as $item) {
<?php return $item;
}
return value($default);
}
foreach ($array as $key => $value) {
<?php }
}
return value($default);
}
<?php public static function last($array, ?callable $callback = null, $default = null)
{
if (is_null($callback)) {
return empty($array) ? value($default) : end($array);
}
return static::first(array_reverse($array, true), $callback, $default);
<?php public static function get($array, $key, $default = null)
{
if (! static::accessible($array)) {
return value($default);
}
if (is_null($key)) {
<?php }
if (! str_contains($key, '.')) {
return $array[$key] ?? value($default);
}
foreach (explode('.', $key) as $segment) {
<?php if (static::accessible($array) && static::exists($array, $segment)) {
$array = $array[$segment];
} else {
return value($default);
}
}
<?php return $this->items[$key];
}
return value($default);
}
<?php return $this->items[$key];
}
$this->offsetSet($key, $value = value($value));
return $value;
}
<?php if ($target instanceof Collection) {
$target = $target->all();
} elseif (! is_iterable($target)) {
return value($default);
}
$result = [];