colap Posted July 30, 2011 Share Posted July 30, 2011 I tried this: $listyear = array(); for($i=2010;$i<=2020;$i++){ array_push($listyear,array($i => $i)); } Array ( [0] => Array ( [2010] => 2010 ) [1] => Array ( [2011] => 2011 ) [2] => Array ( [2012] => 2012 ) [3] => Array ( [2013] => 2013 ) [4] => Array ( [2014] => 2014 ) [5] => Array ( [2015] => 2015 ) [6] => Array ( [2016] => 2016 ) [7] => Array ( [2017] => 2017 ) [8] => Array ( [2018] => 2018 ) [9] => Array ( [2019] => 2019 ) [10] => Array ( [2020] => 2020 ) ) But i want in this format : Array( [2010] = 2010 [2011] = 2011 ........ ) Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted July 30, 2011 Share Posted July 30, 2011 Try this: <?php $yearList = array(); for ($i = 2010; $i <= 2020; ++$i) { $yearList[$i] = $i; } echo '<pre>'; print_r($yearList); echo '</pre>'; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.