variable
am 24.09.2009 19:10:33 von legrega
--0015175cd0eac740fe047455e81d
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Suppose I have a variable $i =3D 0 or 1 or 2
and I have variables $item0, $item1 and $item2
how do I print the variable $item0 using a combination of variable $item an=
d
variable $i?
or with this code it gives me an error:
$i =3D 0;
$item0 =3D "test";
echo $item$i; #how do I properly use this variable $item with $i?
Thanks in advance, Yours, Grega
-- Peace refuge: http://users.skavt.net/~gleskovs/
When the sun rises I receive and when it sets I forgive;) Grega Leskov=C5=
=A1ek
--0015175cd0eac740fe047455e81d--
Re: variable
am 24.09.2009 19:16:44 von Tommy Pham
----- Original Message ----=0A> From: Grega Leskovšek
om>=0A> To: php-general@lists.php.net=0A> Sent: Thursday, September 24, 200=
9 10:10:33 AM=0A> Subject: [PHP] variable=0A> =0A> Suppose I have a variabl=
e $i =3D 0 or 1 or 2=0A> and I have variables $item0, $item1 and $item2=0A>=
how do I print the variable $item0 using a combination of variable $item a=
nd=0A> variable $i?=0A> or with this code it gives me an error:=0A> $i =3D =
0;=0A> $item0 =3D "test";=0A> echo $item$i; #how do I properly use this var=
iable $item with $i?=0A> =0A> Thanks in advance, Yours, Grega=0A> =0A> =0A>=
-- Peace refuge: http://users.skavt.net/~gleskovs/=0A> When the sun rises =
I receive and when it sets I forgive;) Grega Leskovšek
${'item'$i=
} ? Why not use array? Thus, $item[$i], simplify your life ;)=0A
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: variable
am 24.09.2009 19:18:30 von Tommy Pham
----- Original Message ----=0A> From: Tommy Pham
o.com>=0A> To: Grega Leskovšek ; php-general@lists.=
php.net=0A> Sent: Thursday, September 24, 2009 10:16:44 AM=0A> Subject: Re:=
[PHP] variable=0A> =0A> ----- Original Message ----=0A> > From: Grega Lesk=
ovšek =0A> > To: php-general@lists.php.net=0A> > Sent: Thursday, Septe=
mber 24, 2009 10:10:33 AM=0A> > Subject: [PHP] variable=0A> > =0A> > Suppos=
e I have a variable $i =3D 0 or 1 or 2=0A> > and I have variables $item0, $=
item1 and $item2=0A> > how do I print the variable $item0 using a combinati=
on of variable $item and=0A> > variable $i?=0A> > or with this code it give=
s me an error:=0A> > $i =3D 0;=0A> > $item0 =3D "test";=0A> > echo $item$i;=
#how do I properly use this variable $item with $i?=0A> > =0A> > Thanks in=
advance, Yours, Grega=0A> > =0A> > =0A> > -- Peace refuge: http://users.sk=
avt.net/~gleskovs/=0A> > When the sun rises I receive and when it sets I fo=
rgive;) Grega Leskovšek=0A> =0A> ${'item'$i} ? Why not use array? Thu=
s, $item[$i], simplify your life ;)=0A> =0ATyped too slow... my mistake. It=
should be:
${'item' . $i}
> =0A> --=0A> PHP General Mailing List=
(http://www.php.net/)=0A> To unsubscribe, visit: http://www.php.net/unsub.=
php=0A
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: variable
am 24.09.2009 19:23:22 von Ben Dunlap
> Suppose I have a variable $i = 0 or 1 or 2
> and I have variables $item0, $item1 and $item2
> how do I print the variable $item0 using a combination of variable $item and
> variable $i?
> or with this code it gives me an error:
> $i = 0;
> $item0 = "test";
> echo $item$i; #how do I properly use this variable $item with $i?
$var = "item$i";
echo $$var;
Note the two dollar-signs in the second line.
I wonder if a basic array would make for easier-to-read code, though:
$items = array( "test" );
$i = 0;
echo $items[$i];
Ben
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: variable
am 24.09.2009 19:24:45 von Lars Nielsen
Hi Grega
I think you might want to have a look at the array's section of the php
manual.
http://www.php.net/array
regards Lars
tor, 24 09 2009 kl. 19:10 +0200, skrev Grega Leskovšek:
> Suppose I have a variable $i = 0 or 1 or 2
> and I have variables $item0, $item1 and $item2
> how do I print the variable $item0 using a combination of variable $item and
> variable $i?
> or with this code it gives me an error:
> $i = 0;
> $item0 = "test";
> echo $item$i; #how do I properly use this variable $item with $i?
>
> Thanks in advance, Yours, Grega
>
>
> -- Peace refuge: http://users.skavt.net/~gleskovs/
> When the sun rises I receive and when it sets I forgive;) Grega Leskovšek
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php