时间: 2020-12-3|tag: 30次围观|0 条评论

<!--array_chunk()数组函数的使用技巧和方法:-->
<table width="500" border="2" align=center>
    <caption><h1>拆分数组</h1></caption>
<form action="test3.php" method="post">
    <tr>
        <td><input type="submit" name="sub" value="拆分数组并保留键名"></td>
    </tr>
    <tr>
        <td>
        <?php
        error_reporting(@notice);
        $arr=array("a"=>"编程","study"=>"学习","456"=>"教学","b"=>"java编程","c"=>"asp.net编程","dd"=>"php编程");
        echo "原数组为:";
        print_r($arr);
        echo "<br>";
        if($_POST['sub']){
            /*array_chunk()函数拆分数组并返回拆分之后的新的二维数组,第二个参数表示以几个元素为拆分,第三个参数若为true
            则保留一拆分之前的键名,若为false则重新建立新的数字索引*/

            $arr_chunk=array_chunk($arr,2,false);
            echo "拆分之后的数组为:";
            print_r($arr_chunk);
        }
        ?>
        </td>
    </tr>
</form>
</table>

原文链接:https://blog.csdn.net/living_ren/article/details/75007249

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《数组的拆分函数array_chunk()
   

还没有人抢沙发呢~