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

  • SEARCH
  • Home
  • 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 6719695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:07:23+00:00 2026-05-26T09:07:23+00:00

I have an associative array with the following contents: Array ( [L_TIMESTAMP0] => 2011%2d10%2d16T16%3a57%3a38Z

  • 0

I have an associative array with the following contents:

Array
(
    [L_TIMESTAMP0] => 2011%2d10%2d16T16%3a57%3a38Z
    [L_TIMESTAMP1] => 2011%2d10%2d16T16%3a45%3a23Z
    [L_TIMESTAMP2] => 2011%2d10%2d16T16%3a35%3a54Z
    [L_TIMEZONE0] => GMT
    [L_TIMEZONE1] => GMT
    [L_TIMEZONE2] => GMT
    [L_STATUS0] => Completed
    [L_STATUS1] => Completed
    [L_STATUS2] => Completed
    [TIMESTAMP] => 2011%2d10%2d16T17%3a58%3a39Z
)

What I want to do is to ‘group’ all instances of L_TIMESTAMP0, L_TIMEZONE0 and L_STATUS0 (and L_TIMESTAMP1, L_TIMEZONE1, L_STATUS1) into their own array, or as part of a multidimensional array. But I simply can’t seem to figure out how I would go about accomplishing this.

The expected results would be:

Array
    (
        [L_TIMESTAMP0] => 2011%2d10%2d16T16%3a57%3a38Z
        [L_TIMEZONE0] => GMT
        [L_STATUS0] => Completed
    )

Array
    (
        [L_TIMESTAMP1] => 2011%2d10%2d16T16%3a45%3a23Z
        [L_TIMEZONE1] => GMT
        [L_STATUS1] => Completed
    )

I figured this would be simple with a simple for-loop, but that doesn’t give me the results I’m looking for.

Any ideas?
It’s likely something very obvious, but I’ve spent the last few days with this and I can’t figure it out (although that probably says more about my skills than the problem)

edit:
To add; I don’t need the exact code for my particular question, but any pointers as to what direction I should look into would be greatly appreciated.

  • 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-26T09:07:24+00:00Added an answer on May 26, 2026 at 9:07 am
    <?php
    $groupRegex = '/([0-9]+)$/';
    $multiArray = array();
    $assocArray = array (
        "L_TIMESTAMP0" => "2011%2d10%2d16T16%3a57%3a38Z",
        "L_TIMESTAMP1" => "2011%2d10%2d16T16%3a45%3a23Z",
        "L_TIMESTAMP2" => "2011%2d10%2d16T16%3a35%3a54Z",
        "L_TIMEZONE0" => "GMT",
        "L_TIMEZONE1" => "GMT",
        "L_TIMEZONE2" => "GMT",
        "L_STATUS0" => "Completed",
        "L_STATUS1" => "Completed",
        "L_STATUS2" => "Completed",
        "TIMESTAMP" => "2011%2d10%2d16T17%3a58%3a39Z"
    );
    
    foreach( $assocArray as $key => $value ) {
    preg_match( $groupRegex, $key, $group );
    
        if( !isset($group[1]) ){
        continue;
        }
    
    $group = intval( $group[1] );
        if( is_array( $multiArray[$group] ) ) {
        $multiArray[$group][$key] = $value;
        }
        else {
        $multiArray[$group] = array( $key => $value );
        }
    }
    echo "<pre>";
    print_r( $multiArray);
    echo "</pre>";
    ?>
    

    result

    Array
    (
        [0] => Array
        (
            [L_TIMESTAMP0] => 2011%2d10%2d16T16%3a57%3a38Z
            [L_TIMEZONE0] => GMT
            [L_STATUS0] => Completed
        )
    
        [1] => Array
        (
            [L_TIMESTAMP1] => 2011%2d10%2d16T16%3a45%3a23Z
            [L_TIMEZONE1] => GMT
            [L_STATUS1] => Completed
        )
    
        [2] => Array
        (
            [L_TIMESTAMP2] => 2011%2d10%2d16T16%3a35%3a54Z
            [L_TIMEZONE2] => GMT
            [L_STATUS2] => Completed
        )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following issue related to iterating over an associative array of strings
i have the following associative array word => count where word is an english
I have a PHP multidimensional associative array with the following structure: Fields: TYPE -
Possible Duplicate: Dynamically creating/inserting into an associative array in PHP I have the following
I have the following associative array: <? $group_array; Which outputs the following: Array (
I have an associative array (object) of the following construction var menu = new
i have following data as an associative array array 'abc' => array 'label' =>
I have an associative array in awk that gets populated like this: chr_count[$3]++ When
I have an associative array that I want to display using TileList. However, it
I have an associative array assigned to a Smarty variable, something like this: $foo

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.