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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:17:02+00:00 2026-05-24T13:17:02+00:00

I currently have this code: $dates = array(); foreach($data[‘sc_event_dates’] as $date) { if($date >

  • 0

I currently have this code:

$dates = array();
foreach($data['sc_event_dates'] as $date) {
    if($date > time()) {
        $dates[] = date( empty($dates) ? "D d M": "d M", $date);
    }
}
echo implode(", ", $dates);

And it displays something like this:

Thu 11 Aug, 18 Aug, 25 Aug, 01 Sep, 08 Sep, 15 Sep

But what I need to do group the dates of each month so the output would look like this:

Thu 11, 18, 25 Aug, 01, 08, 15 Sep

$data['sc_event_dates'] holds an array of unix timestamps and is ordered in ascending order.

Also dates that are before current time need to be ignored.

Here is some example data:

Array
(
    [0] => 1313020800
    [1] => 1313625600
    [2] => 1314230400
    [3] => 1314835200
    [4] => 1315440000
    [5] => 1316044800
)

Can any one help alter my code, or produce new code, to get my desired output?

  • 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-24T13:17:03+00:00Added an answer on May 24, 2026 at 1:17 pm
    $dates = array();
    foreach($data['sc_event_dates'] as $key => $date) {
        if($date > time()) {
    
            $next = ++$key;
            $format = 'd';
    
            if( empty($dates) ) {
    
                $format = 'D '.$format;
            }
    
            if( !isset( $data['sc_event_dates'][$next] ) || date('n', $date) != date('n', $data['sc_event_dates'][$next]) ) {
    
                $format .= ' M';
            }
    
            $dates[] = date( $format, $date);
        }
    }
    echo implode(", ", $dates);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We currently have code like this: Dim xDoc = XDocument.Load(myXMLFilePath) The only way we
Using dotnet 2.0. I currently have code like this : DataView dv = new
Is there a better way to do this jquery code? Currently I have to
There is probably is simple fix for this but I currently have code similar
Hello I currently have this PHP Script <?php if($purchase_dates != FALSE){?> <?php foreach($purchase_dates as
I currently have this code: $rawsql2 = SELECT * FROM _erc_foffices n INNER JOIN
I currently have this code: $query = query(SELECT SUM(ER_read) FROM tblEread WHERE ER_ID='$sensor' AND
I currently have this code. <?php $username = 'EMAIL ADDRESS'; $password = 'EMAIL ADDRESS';
I have this code: Dim pathString As String = HttpContext.Current.Request.MapPath(Banking.mdb) Dim odbconBanking As New
As a beginner in Ocaml, I have this current working code: ... let ch_in

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.