Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3799816
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:47:40+00:00 2026-05-19T13:47:40+00:00

How Create multiple array from an array and concatenate each elments? I have an

  • 0

How Create multiple array from an array and concatenate each elments?

I have an array in the same level.

$original = Array(
        0=>"03ssss",//first "03"

          1=>"04aaaa",//first "04" of the first "03"
          2=>"05absd",
          3=>"07sdsa",
          4=>"08sdsd",

        5=>"03tttt", //second "03"

          6=>"04xxxx, //first "04" of the second "03"
            7=>"05sdds",
            8=>"07sdfd",
            9=>"08sdff",
          10=>"04xsax", //second "04" of second "03"
            11=>"05sdfs",
            12=>"07sdfds",
            13=>"08asap",
    )

base on $original

if(substr("03ssss",0,2)="03") Will be came the index of main array

else will the index of child array andconcat with these elements with if we found substr("03ssss",0,2)="04"

So the expected result look like:

$move_level = Array(
 0=>array( // first "03" 
    0=>"04aaaa 05absd 07sdsa 08sdsd"),//first 04 of the first "03"
 1=>array(// second "03"
         0=>"04xxxx 05sdds 07sdfd 08sdff",  // Concat with "04"
         1=>"04xsax 05sdfs 07sdfds 08asap" // Concat with "04"
         )
);

If I try:

$move_level = array(); //main array
$ary = array(); // sub array
foreach($original as $value) {
    if (substr($value,0,2) =="03") {
        $move_level[] = $ary;// create main array
        $ary = array();// create sub 
    } else { // to to join all element with "04"
        $ary[] = ($value);
    }

}

$move_level[] = $ary;


echo '<pre>';
print_r($move_level);
echo '</pre>';

OUTPUT:

Array
(
[0] => Array
    (
    )

[1] => Array
    (
        [0] => 04xxxx
        [1] => 05xxxx
        [2] => 07xxxx
        [3] => 08xxxx
    )

[2] => Array
    (
        [0] => 04xxxx
        [1] => 05xxxx
        [2] => 07xxxx
        [3] => 08xxxx
        [4] => 04xxxx
        [5] => 05xxxx
        [6] => 07xxxx
        [7] => 08xxxx
    )

 )

I WANT GET :

Array
(

[0] => Array
    (
        [0] => 04xxxx 05xxxx 07xxxx 08xxxx
    )

[1] => Array
    (
        [0] => 04xxxx 05xxxx 07xxxx 08xxxx,
        [1]=>04xxxx 05xxxx 07xxxx 08xxxx
    )

 )

How Can create from $original to multiple array something like this?
thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:47:41+00:00Added an answer on May 19, 2026 at 1:47 pm
    $original = array(  0   => "03ssss",    //first "03"
                        1   => "04aaaa",    //first "04" of the first "03"
                        2   => "05absd",
                        3   => "07sdsa",
                        4   => "08sdsd",
                        5   => "03tttt",    //second "03"
                        6   => "04xxxx",    //first "04" of the second "03"
                        7   => "05sdds",
                        8   => "07sdfd",
                        9   => "08sdff",
                        10  => "04xsax",    //second "04" of second "03"
                        11  => "05sdfs",
                        12  => "07sdfds",
                        13  => "08asap",
                    );
    
    $r = -1;
    $move_level = array();
    foreach($original as $value) {
        if(substr($value,0,2) == "03") {
            ++$r;
            $j = 0;
            $move_level[$r][$j] = '';
        } else {
            if (($j % 4) > 0) $value = ' '.$value;
            $move_level[$r][floor($j / 4)] .= $value;
            ++$j;
        }
    }
    
    echo '<pre>';
    var_dump($move_level);
    echo '</pre>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We frequently have users that create multiple accounts and then end up storing the
I am using AS3 to create a tween affect between multiple images that have
I'd like to create a tree structure from JSON, but with multiple columns that
A single Biztalk Server can have multiple Host processes. Is it possible to create
For a company with many development projects, should you create multiple FitNesse wikis (one
I am working on a program that needs to create a multiple temporary folders
I want to create a c# application with multiple windows that are all transparent
I need to create a batch file which starts multiple console applications in a
I need to create an XmlDocument with a root element containing multiple namespaces. Am
Is there a way to create a Zip archive that contains multiple files, when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.