pioneerx01 Posted June 7, 2011 Share Posted June 7, 2011 Lets say that: $my_number = '13' How do I get this type of an array automatically just from defining $my_number? $my_array = array(1,2,3,4,5,6,7,8,9,10,11,12,13) Quote Link to comment https://forums.phpfreaks.com/topic/238615-get-full-array-123111213-with-defining-only-one-number/ Share on other sites More sharing options...
Zane Posted June 7, 2011 Share Posted June 7, 2011 $my_array = range(1, 13); or in your case, $my_number = 13; $my_array = range(1,$my_number); Quote Link to comment https://forums.phpfreaks.com/topic/238615-get-full-array-123111213-with-defining-only-one-number/#findComment-1226249 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 7, 2011 Share Posted June 7, 2011 Believe this is what you're looking for. for($i=$my_number; $i>=1; $i--{ $array[]=$i; } or $my_array[] = range(1, $my_number); Quote Link to comment https://forums.phpfreaks.com/topic/238615-get-full-array-123111213-with-defining-only-one-number/#findComment-1226251 Share on other sites More sharing options...
Pikachu2000 Posted June 7, 2011 Share Posted June 7, 2011 You mean something like this, I assume? $mynum = 13; $array = range( 1, $mynum ); [/code] Quote Link to comment https://forums.phpfreaks.com/topic/238615-get-full-array-123111213-with-defining-only-one-number/#findComment-1226252 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.