Variables
am 25.04.2002 17:57:31 von jcuz
--=====================_77585612==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed
HI--
* I have the following variables: $c1 thru $c10.
* I also have a FOR loop like this:
for($count = 0; $count < sizeof($artist); $count++)
{ echo "$artist[$count]
"; }
// $artist is a list of ten (10) artist's names.
* What I'm trying to do is something like this: Combine the variables
with the info inside the FOR loop:
> for($count = 0; $count < sizeof($artist); $count++)
> { //Trying to assign the value of $c1, $c2, $c3,
> etc. using the value of the variable $count.
> //But so far, it only processes the value of
> $count alone, and it ignores $c
> //The line below should read like this: $c1 =
> $artist[0], next line: $c2 = $artist[1], etc.
> $c . $count+1 = $artist[$count];
> }
>
> Help!!!
Julio Cuz, Jr.
Riverside Community College
jcuz@rccd.cc.ca.us
--=====================_77585612==_.ALT
Content-Type: text/html; charset="us-ascii"
HI--
- I have the following variables: $c1 thru $c10.
- I also have a FOR loop like this:
for($count
= 0; $count < sizeof($artist); $count++)
{
echo "<i>$artist[$count]</i><br>"; }
// $artist
is a list of ten (10) artist's names.
- What I'm trying to do is something like this: Combine the
variables with the info inside the FOR loop:
for($count
= 0; $count < sizeof($artist); $count++)
{
//Trying to assign the value of $c1, $c2, $c3, etc. using the value of
the variable $count.
//But so far, it only processes the value of $count alone, and it ignores
$c
//The
line below should read like this: $c1 = $artist[0], next
line: $c2 = $artist[1], etc.
$c
.. $count+1 = $artist[$count];
}
Help!!!
Julio Cuz, Jr.
Riverside Community College
jcuz@rccd.cc.ca.us
--=====================_77585612==_.ALT--
Re: Variables
am 25.04.2002 19:18:06 von Areski Belaid
This is a multi-part message in MIME format.
------=_NextPart_000_0015_01C1EC8D.ED68D960
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi the Community,
A good exemple, it's always better that a long...
You must use the eval fonction. (www.php.net)
$artist[]=3D"Areski1";
$artist[]=3D"Areski2";
$artist[]=3D"Areski3";
$artist[]=3D"Areski4";
$c0=3D"Kiki1";
$c1=3D"Kiki2";
$c2=3D"Kiki3";
$c3=3D"Kiki4";
for($count =3D 0; $count < sizeof($artist); $count++)
{
eval( "echo \$c$count.\"
\";" ); //just to see no important
eval( "\$c$count =3D \"$artist[$count]\";" );=20
eval( "echo \"-->\".\$c$count.\"
\";" );//just to see no important
}
?>
I have the following variables: $c1 thru $c10.=20
a.. I also have a FOR loop like this:=20
for($count =3D 0; $count < sizeof($artist); $count++)
{ echo "$artist[$count]
"; }=20
// $artist is a list of ten (10) artist's names.=20
a.. What I'm trying to do is something like this: Combine the variable=
s with the info inside the FOR loop:=20
for($count =3D 0; $count < sizeof($artist); $count++)
{ //Trying to assign the value of $c1, $c2, $c3, etc. us=
ing the value of the variable $count.
//But so far, it only processes the value of $count al=
one, and it ignores $c
//The line below should read like this: $c1 =3D $artist[=
0], next line: $c2 =3D $artist[1], etc.
$c . $count+1 =3D $artist[$count];
}=20
Help!!!
Julio Cuz, Jr.
Riverside Community College
jcuz@rccd.cc.ca.us=20
------=_NextPart_000_0015_01C1EC8D.ED68D960
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi the Community,
A good exemple, it's always better that a=
=20
long...
You must use the eval fonction. (
href=3D"http://www.php.net">www.php.net)
size=3D2><?
$artist[]=3D"Areski1";
$artist[]=3D"Areski2";
$arti=
st[]=3D"Areski3";
$artist[]=3D"Areski4";
size=3D2>$c0=3D"Kiki1";
$c1=3D"Kiki2";
$c2=3D"Kiki3";
$c3=3D"Kiki4=
";
for($count =3D 0; $count < sizeof($arti=
st);=20
$count++)
{
eval( "echo=20
\$c$count.\"<br>\";" ); //just to see no important
eva=
l(=20
"\$c$count =3D \"$artist[$count]\";" );
eval( "echo=20
\"-->\".\$c$count.\"<br><br>\";" );//just to see no=20
important
}
?>
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LE=
FT: #000000 2px solid; MARGIN-RIGHT: 0px">
I have the following=20
variables: $c1 thru $c10.
- I also have a FOR loop like this:=20
=
for($count=20
=3D 0; $count < sizeof($artist);=20
$count++)
AB> {=20
echo "<i>$artist[$count]</i><br>"; }=20
// $ar=
tist=20
is a list of ten (10) artist's names.=20
- What I'm trying to do is something like this: Combine the=20
variables with the info inside the FOR loop:=20
type=3D"cite">
 =
; for($count=20
=3D 0; $count < sizeof($artist);=20
$count++)
AB> { =
=20
//Trying to assign the value of $c1, $c2, $c3, etc. using the value of th=
e=20
variable=20
$count.
>  =
;=20
//But so far, it only processes the value of $count alone, and it ignores=
=20
$c
AB> //The=20
line below should read like this: $c1 =3D $artist[0], next line:&nb=
sp; $c2=20
=3D $artist[1],=20
etc.
-TAB> &=
nbsp; $c=20
. $count+1 =
$artist[$count];
&nbs=
p; }=
=20
Help!!!
Julio Cuz, Jr.
Riverside Community=20
College
jcuz@rccd.cc.ca.us
------=_NextPart_000_0015_01C1EC8D.ED68D960--
Re: Variables
am 25.04.2002 19:56:33 von Kwabena Adowah Adu
Hi Julio,
I have 4 suggestions:
i. Perform the sizeof() operation once and outside
the loop. This will save you some cpu cycles. Also,
if you know for sure that sizeof($artist) is unlikely
to change, set it as a constant.
ii. Create the $c.x string prior to assigning a value
to the variable it represents.
eg.
$artist_size=sizeof($artist);
for($count = 0; $count<$artist_size; $count++)
$varname = "c".($count+1); //
${$varname} = $artist[$count];
}
echo $c1.$c2.$c10;
iii. Go here for more notes on how to create variable variables:
http://www.php.net/manual/en/language.variables.variable.php
iv. Have lots of fun.
cheers!
Kwab
Julio Cuz, Jr. [2002.04.25.1757 +0200]:
> HI--
>
> * I have the following variables: $c1 thru $c10.
>
> * I also have a FOR loop like this:
>
> for($count = 0; $count < sizeof($artist); $count++)
> { echo "$artist[$count]
"; }
> // $artist is a list of ten (10) artist's names.
>
> * What I'm trying to do is something like this: Combine the variables with
> the info inside the FOR loop:
>
> for($count = 0; $count < sizeof($artist); $count++)
> { //Trying to assign the value of $c1, $c2, $c3, etc.
> using the value of the variable $count.
> //But so far, it only processes the value of $count
> alone, and it ignores $c
> //The line below should read like this: $c1 = $artist[0],
> next line: $c2 = $artist[1], etc.
> $c . $count+1 = $artist[$count];
> }
>
> Help!!!
>
> Julio Cuz, Jr.
> Riverside Community College
> jcuz@rccd.cc.ca.us
-------------------------------
Kwabena Adowah Adu - Consultant
Lucid Tech Solutions, LLC
P.O. Box 135
Wallingford, PA 19086
Tel : 610.583.2737 | 484.444.0788
kwab@lucidtechsolutions.com
http://www.lucidtechsolutions.com
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster