Matija Papec wrote:
Jeff wrote:
>>> I need to make an array of 1 to X items
in perl , this would be: 1..X .
Is there such a thing in php, or do I need to make a loop?
range() maybe?
perfect!
Even more useful than the perl construct.
Just be aware that
$arr = array();
foreach (range(0,count($arr)-1) as $i) print "$i\n";
and
my @arr = ();
for my $i (0 .. $#arr) { print "$i\n"; }
behaves differently.
They do behave the same (ran each at the command line to be sure).
Maybe you didn't mean to subtract 1 from count($arr), in the PHP example.
These two are the same:
PHP
$indexes = range(0, count($arr)-1);
Perl
my @indexes = (0..$#arr);
So are these:
PHP
$elements = range(0, count($arr));
Perl
my @elements = (0 .. scalar @arr);
--
Curtis