views:

319

answers:

3

If i have a variable $num = 50 how can i put numbers 1-50 into an array? (50 is an example.. i wont know how many questions)

A: 

for ($i = 1; $i <= $num; ++$i) { $array[] = $i; }

tarnfeld
+18  A: 

Take a look at the range function.

$array = range(1, $num);
erenon
+1  A: 

<?php $array = range(1, 50); ?>

Have a look at range function

Matt Ellen
Example is broken. , instead of ..
erenon
Example was broken but function is the right one to use. No need to give negative feedback - the answer is still useful.
ChronoFish
`..` is the perl range operator: `my @range = (1 .. 50); my @alpha = ('a' .. 'z'); `
Rob
@Rob, also the Python range operator.
Alix Axel
eyze: and the pascal as well...
erenon
Sorry! Been writing too much haskell. Thanks for the edit.
Matt Ellen