当前位置:Gxlcms > PHP教程 > PHP中数组合并的问题

PHP中数组合并的问题

时间:2021-07-01 10:21:17 帮助过:17人阅读

require_once ('mysqli_connect.php');$q = "SELECT ID FROM information";$r = @mysqli_query($dbc, $q);$contents = array();while($row=mysqli_fetch_array($r,MYSQL_ASSOC)){	$contents[]=$row;}shuffle($contents);echo ".................................";$newarry = array();$newarry = array_chunk($contents, 4,FALSE);print_r($newarry);

这是代码部分 出来的结果是
.................................Array ( [0] => Array ( [0] => Array ( [ID] => 2IT14035A ) [1] => Array ( [ID] => 1IT14033S ) [2] => Array ( [ID] => 1IE15003B ) [3] => Array ( [ID] => 1IE15001A ) ) [1] => Array ( [0] => Array ( [ID] => 1IE14210D ) [1] => Array ( [ID] => 1IE15010C ) [2] => Array ( [ID] => 1IT15001G ) [3] => Array ( [ID] => 5IE14032S ) ) )
现在希望这么显示
Array ( [0] => 2IT14035A,5IE14032S,1IE15003B,1IE15010C [1] => 1IE14210D,1IE15001A,1IT15001G,1IT14033S )
该怎么办呢?
谢谢大神们


回复讨论(解决方案)

array_slice() 分隔2个大数组
implode() 小数组分割

$contents[] = $row['ID'];

array_chunk 后,在对每组做 join

谢谢版主
实际操作该怎么搞呢

人气教程排行