<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Collection類 ### 介紹 `October\Rain\Support\Collection`類提供一個流暢,方便的包裝用于與數據的數組工作。例如,查看以下代碼。我們將從數組創建一個新的集合實例,`strtoupper`在每個元素上運行該函數,然后刪除所有空元素: ~~~ $collection = new October\Rain\Support\Collection(['stewie', 'brian', null]); $collection = $collection ->map(function ($name) { return strtoupper($name); }) ->reject(function ($name) { return empty($name); }) ; ~~~ 在`Collection`類允許您鏈中的方法來執行流利映射和底層數組的減少。通常,每個`Collection`方法都返回一個全新的`Collection`實例。 ### [](https://octobercms.com/docs/services/collections#creating-collections)創建收藏 如上所述,將數組傳遞給`October\Rain\Support\Collection`類的構造函數將為給定數組返回一個新實例。因此,創建集合非常簡單: ~~~ $collection = new October\Rain\Support\Collection([1, 2, 3]); ~~~ 默認情況下,[數據庫模型的](https://octobercms.com/docs/database/model)集合始終作為`Collection`實例返回;但是,請`Collection`在適合您的應用程序的任何地方隨意使用該類。 ### 高階消息 集合還支持“高級消息”,這是對集合執行常見操作的捷徑。提供更高階的信息收集方法有:[`average`](https://octobercms.com/docs/services/collections#method-average),[`avg`](https://octobercms.com/docs/services/collections#method-avg),[`contains`](https://octobercms.com/docs/services/collections#method-contains),[`each`](https://octobercms.com/docs/services/collections#method-each),[`every`](https://octobercms.com/docs/services/collections#method-every),[`filter`](https://octobercms.com/docs/services/collections#method-filter),[`first`](https://octobercms.com/docs/services/collections#method-first),[`flatMap`](https://octobercms.com/docs/services/collections#method-flatmap),[`groupBy`](https://octobercms.com/docs/services/collections#method-groupby),[`keyBy`](https://octobercms.com/docs/services/collections#method-keyby),[`map`](https://octobercms.com/docs/services/collections#method-map),[`max`](https://octobercms.com/docs/services/collections#method-max),[`min`](https://octobercms.com/docs/services/collections#method-min),[`partition`](https://octobercms.com/docs/services/collections#method-partition),[`reject`](https://octobercms.com/docs/services/collections#method-reject),[`some`](https://octobercms.com/docs/services/collections#method-some),[`sortBy`](https://octobercms.com/docs/services/collections#method-sortby),[`sortByDesc`](https://octobercms.com/docs/services/collections#method-sortbydesc),[`sum`](https://octobercms.com/docs/services/collections#method-sum),和[`unique`](https://octobercms.com/docs/services/collections#method-unique)。 每個高階消息都可以作為集合實例上的動態屬性來訪問。例如,讓我們使用`each`高階消息在集合內的每個對象上調用一個方法: ~~~ $users = User::where('votes', '>', 500)->get(); $users->each->markAsVip(); ~~~ 同樣,我們可以使用`sum`較高順序的消息來收集用戶集合的“票數”總數: ~~~ $users = User::where('group', 'Development')->get(); return $users->sum->votes; ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看