Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,777 questions

55,543 answers

573 users

How to create an array of days starting with today and going back the last 30 days in PHP

1 Answer

0 votes
$days = array();

for ($i = 0; $i < 30; $i++) {
    $days[] = date("d", strtotime('-'. $i .' days'));
}

print_r($days);



/*
run:

Array
(
    [0] => 10
    [1] => 09
    [2] => 08
    [3] => 07
    [4] => 06
    [5] => 05
    [6] => 04
    [7] => 03
    [8] => 02
    [9] => 01
    [10] => 31
    [11] => 30
    [12] => 29
    [13] => 28
    [14] => 27
    [15] => 26
    [16] => 25
    [17] => 24
    [18] => 23
    [19] => 22
    [20] => 21
    [21] => 20
    [22] => 19
    [23] => 18
    [24] => 17
    [25] => 16
    [26] => 15
    [27] => 14
    [28] => 13
    [29] => 12
)

*/

 



answered Apr 10, 2025 by avibootz
edited Apr 10, 2025 by avibootz
...