gremo
gremo

Reputation: 48419

Fill arrays applying a function to a given starting value?

Is there a function to fill arrays applying a function to a given starting value?

$now  = date('Y');
$down = 5;

// 2012, 2011, 2010, 2009, 2008
$years = array_fill_func();

Upvotes: 1

Views: 60

Answers (2)

gen_Eric
gen_Eric

Reputation: 227290

If you're just using numbers you can do something like this:

$now  = date('Y');
$down = 5;
$years = range($now, $now-$down);

Upvotes: 0

zerkms
zerkms

Reputation: 255015

How about

$years = range(date('Y'), date('Y') - 4, -1);

Upvotes: 3

Related Questions