Laravel 集合与函数

2019-12-11  本文已影响0人  phpnet

集合

Illuminate\Support\Collection 类提供了一个更具可读性和更便于处理数组数据的封装。

创建集合

$collection = collect([1, 2, 3]);

扩展集合

集合都是「可宏扩展」(macroable) 的,它允许你在执行时将其它方法添加到 Collection 类。

use Illuminate\Support\Str;

Collection::macro('toUpper', function () {
    return $this->map(function ($value) {
        return Str::upper($value);
    });
});

$collection = collect(['first', 'second']);
$upper = $collection->toUpper();

// ['FIRST', 'SECOND']

常用方法

函数

Laravel 包含各种各样的全局 PHP 「辅助」函数,框架本身也大量的使用了这些功能函数;如果你觉的方便,你可以在你的应用中任意使用这些函数。

路径

URLs

其他

上一篇 下一篇

猜你喜欢

热点阅读