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 ........ ) Link to comment https://forums.phpfreaks.com/topic/243282-how-can-i-create-php-hash-array/ 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/243282-how-can-i-create-php-hash-array/#findComment-1249412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.