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 <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
> --
>
> Joe Stump, PHP Hacker
> [EMAIL PROTECTED]
> http://www.miester.org/
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]