codelayui.code

<button id="g80sy"></button>

codelayui.code

codelayui.code

codelayui.code

  • codelayui.code

    <abbr id="g80sy"></abbr>
  • <button id="g80sy"></button>

    codelayui.code

    codelayui.code

    codelayui.code

    codelayui.code

    <rt id="g80sy"><delect id="g80sy"></delect></rt>

    codelayui.code

  • PHP中array_chunk() 函數(shù)如何分割數(shù)組

    程序猿 2021-02-26 21:43:27 2012瀏覽 加載中

    我們在學(xué)習(xí)字符串的時(shí)候,經(jīng)常會(huì)進(jìn)行切割元素的操作,當(dāng)然在數(shù)組中也是同樣可以進(jìn)行分割的。本篇所要帶來的是array_chunk() 函數(shù),可以說它就是專門用來分割數(shù)組的函數(shù)。下面我們對array_chunk()的概念、語法、參數(shù)、返回值進(jìn)行介紹,然后分享一個(gè)實(shí)例供大家學(xué)習(xí)。

    1、概念

    將一個(gè)數(shù)組分隔成若干個(gè)數(shù)組。

    2、語法

    codelayui.code

    1. array_chunk(array,size,preserve_keys);

    3、參數(shù)

    codelayui.code

    1. array
    2. size
    3. preserve_key

    4、返回值

    返回一個(gè)多維的數(shù)值數(shù)組,從 0 開始,每個(gè)維度都包含 size 元素。

    5、實(shí)例

    codelayui.code

    1. $array = ['name' => 'tom', 'age' => 20, 3, 4, 5, 'a', 'b'];

    每3個(gè)分割一組

    codelayui.code

    1. $chunk_result = array_chunk($array, 3);

    結(jié)果

    codelayui.code

    1. Array
    2. (
    3.     [0] => Array
    4.         (
    5.             [0] => tom
    6.             [1] => 20
    7.             [2] => 3
    8.         )
    9.   
    10.     [1] => Array
    11.         (
    12.             [0] => 4
    13.             [1] => 5
    14.             [2] => a
    15.         )
    16.   
    17.     [2] => Array
    18.         (
    19.             [0] => b
    20.         )
    21.   
    22. )

    以上就是PHP中array_chunk() 函數(shù)分割數(shù)組的方法,大家對基本的內(nèi)容部分學(xué)習(xí)完后,不妨展開代碼部分的練習(xí)吧。

    標(biāo)簽: php
    最后修改:2025-05-23 20:24:22

    非特殊說明,本博所有文章均為博主原創(chuàng)。

    主站蜘蛛池模板: 五华县| 沧源| 嘉义市| 望江县| 志丹县| 远安县| 鄂尔多斯市| 年辖:市辖区| 六枝特区| 汾阳市| 诏安县| 齐齐哈尔市| 收藏| 安顺市| 五常市| 宁远县| 湾仔区| 霍山县| 耒阳市| 天祝| 定南县| 温宿县| 香格里拉县| 博野县| 长子县| 杂多县| 十堰市| 香河县| 遂昌县| 玉屏| 合江县| 伊金霍洛旗| 客服| 义乌市| 大英县| 长葛市| 和政县| 玉林市| 平度市| 原阳县| 和顺县|