Home > Backend Development > PHP Tutorial > PHP中数组合并的问题

PHP中数组合并的问题

WBOY
Release: 2016-06-23 13:17:51
Original
985 people have browsed it

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);
Copy after login

这是代码部分 出来的结果是
 .................................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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template