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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:29:32+00:00 2026-05-27T06:29:32+00:00

$array = array(2011-September_38,2011-June_4,2010-November_9,2011-November_29,2010-December_19); i want to sort this array strings as following, it should

  • 0
$array = array("2011-September_38","2011-June_4","2010-November_9","2011-November_29","2010-December_19");

i want to sort this array strings as following, it should sort the year first, then it should sort the month,

DESIRED OUTPUT

Array ( [0] => 2010-Marh_19 
        [1] => 2010-November_9 
        [2] => 2011-June_4 
        [3] => 2011-September_38
        [4] => 2011-November_29 )

I’ve tried something, could anyone bind my function to sort year then month http://codepad.org/skEiUkTC

  • 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-27T06:29:32+00:00Added an answer on May 27, 2026 at 6:29 am

    Try this code:

    <?php
    $array = array("2011-September_38","2011-June_4","2010-November_9","2011-November_29","2010-December_19");
    function monthCompare($a, $b) {
       $da = strtotime(strstr($a, '_', true));
       $db = strtotime(strstr($b, '_', true));
       return $da > $db;
    }
    usort($array, "monthCompare");
    print_r($array);
    ?>
    

    OUTPUT

    Array
    (
        [0] => 2010-November_9
        [1] => 2010-December_19
        [2] => 2011-June_4
        [3] => 2011-September_38
        [4] => 2011-November_29
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of objects like this - [{name:admission[year],value:2011-12},{name:admission[class],value:Nursery}] How can i access
I have my json array with is this : [{id:1,cid:1,da:08:00:00,a:12:00:00,data:2011-07-03,persone:3,nome:Via Bligny}, {id:8,cid:1,da:08:30:00,a:14:45:00,data:2011-09-26,persone:2,nome:Via Bligny}, {id:9,cid:1,da:08:30:00,a:14:15:00,data:2011-09-26,persone:2,nome:Via
What should i do ? $edit_end_date = '2011-02-31'; $validator_date = new Zend_Validate_Date(array('format' => 'yyyy-mm-dd'));
I have an array with a series of event IDs organized like this: $event['year']['month']['day']
i have this array: [Jessica CS] => Array ( [2011-04-20] => Array ( [0]
I have an array of dates whose format is like this: 10/15/2005 or 2/10/2011.
I have this array:- Array ( [0] => Prefectorial Board/Prefect/2011 [1] => Prefectorial Board/Head
I've dates array with values below: 07/07/2011, 08/05/2011, 09/07/2011, 12/07/2011 Using this as input
i have a DateTimeArray this array contain DateTimeArray[index 0] = 20.05.2011 12:12:50 DateTimeArray[index 1]=
i have an array like this: [2011-06-16 16:37:20,23.2], [2011-06-21 16:37:20,35.6], [2011-06-26 16:37:20,41.8], [2011-07-01 16:37:20,25],

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.