RE: [PHP] arrays, loops, vars and props

From: Date: Wed, 10 Mar 2004 19:53:22 +0000
Subject: RE: [PHP] arrays, loops, vars and props
Groups: php.general 
Request: Send a blank email to php-general+get-180042@lists.php.net to get a copy of this message
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.

« previous php.general (#180042) next »