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 8402255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:00:36+00:00 2026-06-09T22:00:36+00:00

I have this array: array{ 0 => string ‘1’ (length=1) 1 => string ’18’

  • 0

I have this array:

array{
  0 => string '1' (length=1) 
  1 => string '18' (length=2)
  2 => string '18' (length=2)
  3 => string '1' (length=1)
  4 => string '1' (length=1)
  5 => string '1' (length=1)
  6 => string '1' (length=1)
  7 => string '1' (length=1)
  8 => string '18' (length=2)
  9 => string '18' (length=2)
}

I want to make it looks like this:

array{
  0 => array (
          0 => '1'
             )
  1 => array (
          0 => '18' 
          1 => '18' 
             )
  2 => array (
          0 => '1'
          1 => '1'
          2 => '1'
          3 => '1'
          4 => '1'
          5 => '1' 
             )
  3 => array (
          0 => '18'
          1 => '18' 
             )
}

So the idea is, i want to group the array by finding if the next array key is the same as the current key, if the next array key is the same as the current one, it merges it inside a new array, like grouping.

i couldn’t really find an answer here, or on google, the idea is there is key 1 then 2 the 1 again, i want to group the similar keys until a different key comes in, the key (2) broke the grouping and started a new group, then broke by key 1 to start a new group as well,

the idea is for chatting messages, facebook and msn they group the messages by the user who sent them, untill another user comes in and break the group.
but can’t find out how.

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-06-09T22:00:37+00:00Added an answer on June 9, 2026 at 10:00 pm

    You’ll have to loop it yourself, finding the blocks where the current element $i matches the next element $j, continuing to increment $j while the equality holds, and then slicing that section off into its own array with array_slice():

    $new = array(); $count = count( $old) - 1;
    for( $i = 0, $j = 1; $i < $count; $i = $j, $j = $i + 1) {
        while( $old[$i] === $old[$j]) $j++;
        $new[] = array_slice( $old, $i, $j - $i);
    }
    

    This will print:

    Array
    (
        [0] => Array
            (
                [0] => 1
            )
    
        [1] => Array
            (
                [0] => 18
                [1] => 18
            )
    
        [2] => Array
            (
                [0] => 1
                [1] => 1
                [2] => 1
                [3] => 1
                [4] => 1
            )
    
        [3] => Array
            (
                [0] => 18
                [1] => 18
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have string that look like Array that fetched from other webservice like this
I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
I have this array array 0 => array 'prodid' => string '2' (length=1) 'qty'
I have this array: array 0 => string '3,6' (length=3) 3 => string '4,5'
I have this string : 0=&task=rose&duration=1.25&user=15&1=&task=daisy&duration=0.75&user=25&2=&task=orchid&duration=1.15&user=7 I want this array structure : array( array(
So, I have this next button which calls a string array and when count
I have this array: string[,] productData = new string[5,7]; I bind it to a
I have this 4 Dimensional array to store String values which are used to
I have this string of numbers var array = 1,6,2,9,5 which is retrieved from
i have this code that will check the array contains the specific string and

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.