Re: arrays, loops, vars and props
| From: | Luis Mirabal | Date: | Wed, 10 Mar 2004 20:30:10 +0000 |
| Subject: | Re: arrays, loops, vars and props | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-180045@lists.php.net to get a copy of this message | ||
i would do it this way
function MyClass()
{
$this->myArray = range(0, 99);
}
luis.
"Chris W. Parker" <cparker@swatgear.com> escribió en el mensaje
news:001BD19C96E6E64E8750D72C2EA0ECEE2B8735@ati-ex-01.ati.local...
Jason Davidson <mailto:jdavidson@zworg.com>
on Wednesday, March 10, 2004 12:25 AM said:
> would the following example be faster or slower had i simply done
> $this->myArray[$i] = $i;
>
> class MyClass {
> var $myArray = array();
>
> function MyClass() {
> $myTempArray = array();
> for($i=0;$i<100;$i++)
> $myTempArray[$i] = $i;
> $this->myArray = $myTempArray;
> }
> }
here's how i would do it (coding styles aside):
function MyClass()
{
$limit = 100;
$i = -1;
while(++$i < $limit)
{
$this->myArray[] = $i;
}
}
chris.