<!–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
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
评论前必须登录!
立即登录