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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:21:26+00:00 2026-05-27T05:21:26+00:00

I have an array of strings of the format Year-Month_ID. I’d like to split

  • 0

I have an array of strings of the format “Year-Month_ID”. I’d like to split each item in two at the ‘_’. Then, for the items that have the same prefix (year & month), join the IDs with ‘_’ after the prefix (“Year-Month_ID_ID…”). For example, if I have the data:

array(
    '2010-December_9',
    '2010-December_19',
    '2011-June_4',
    '2011-September_38',
    '2011-November_29',
    '2011-November_9'
)

I want the result to be:

array(
    '2010-December_9_19',
    '2011-June_4',
    '2011-September_38',
    '2011-November_29_9'
)

How can I do this?

  • 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-27T05:21:26+00:00Added an answer on May 27, 2026 at 5:21 am
    $arr = array();
    foreach ($dates as $val)
    {   
        $tmp = explode("_", $val);
        if ( ! isset($arr[$tmp[0]]))
        {   
            $arr[$tmp[0]] = array();
        }   
        $arr[$tmp[0]][] = $tmp[1];
    }   
    $final = array();
    foreach ($arr as $key=>$val)
    {   
        $final[] = $key."_".implode("_", $val);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that converts an array of date strings from a format
I have two Sets of Strings, with each in the following format: Set1(Names) Set2(Sizes)
I have an array of strings that I want to use for button titles
I have an array that keeps URL addresses in String format for me. Before
Suppose I have a combobox where items are binded to an array of strings.
I currently have a ListView that takes in an array of strings. It is
I have byte array as input. I would like to convert that array to
I have an array containing strings of this format: [0] => title|url|score|user|date [1] =>
I have an array with n strings in format of YYYY-MM-DD (Example, 2010-10-31). How
I have array of strings, String[] data and it's 10 elements has value P

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.