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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 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
...