Re: variable question

From: Date: Fri, 19 Jan 2001 22:56:43 +0000
Subject: Re: variable question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-35746@lists.php.net to get a copy of this message
thats right you could do that, but it sucks. (IMHO) $test->s0 $test->s1 $test->s2 for($c = 0; $c < 3; $c++) { $name = "s$c"; echo $test->$name; } but this is better, more modular. $test->s[0] $test->s[1] $test->s[2] foreach($test->s as $pos => $val) echo $val; with the second example you can add another element to $test->s and the loop will auto adjust for this. but both methods work. Chris Lee Mediawaveonline.com Joe Stump <jstump@zebulon.miester.org> wrote in message news:20010119142413.B10529@zebulon.miester.org... > Put them in an array? PHP allows for variable variables, but I'm not sure they > work with classes. > > This works: > > $foo0 = 'a'; > $foo1 = 'b'; > $foo2 = 'c'; > $foo3 = 'd'; > $foo4 = 'e'; > > for($i = 0 ; $i < 5 ; ++$i) > { > $var = 'foo'.$i; > echo $$var; > } > > Try it with an object... > > --Joe > > > On Fri, Jan 19, 2001 at 05:15:25PM -0500, Michael Zornek wrote: > > ok so i have an object that has (among other things) the following properties: > > > > $vendor_data->s9 > > $vendor_data->s10 > > $vendor_data->s11 > > $vendor_data->s12 > > ... > > $vendor_data->s40 > > > > The values are 1 or 0 > > > > I'd like to write a loop to say: > > > > for ($count=9; $count>40; $count++) { > > if ($vendor_data->s(insert_number_here) == 1) { > > echo something; > > } > > } > > > > any thoughts? > > > > Mike > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > -- > > Joe Stump, PHP Hacker > joestump98@yahoo.com > http://www.miester.org/ > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#35746) next »