Array merging in PHP-php Tutorial

Source: Internet
Author: User
Array merging in PHP
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);

This is the result of the code section:
................................. 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 )))
Now I want to display it like this
Array ([0] => 2IT14035A, 5IE14032S, 1IE15003B, 1IE15010C [1] => 1IE14210D, 1IE15001A, 1IT15001G, 1IT14033S)
What should I do?
Thank you!


Reply to discussion (solution)

Array_slice () separates two large arrays
Implode () Small array segmentation

$ Contents [] = $ row ['id'];

After array_chunk, perform join on each group

Thank you moderator
What should I do?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.