pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedVariables
3+ messages / 3 participants
[nested] [flat]
* Variables
@ 2002-04-25 15:57 Julio Cuz, Jr. <jcuz@rccd.cc.ca.us>
0 siblings, 2 replies; 3+ messages in thread
From: Julio Cuz, Jr. @ 2002-04-25 15:57 UTC (permalink / raw)
To: pgsql-php
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Variables
@ 2002-04-25 17:18 Areski Belaid <areski5@hotmail.com>
parent: Julio Cuz, Jr. <jcuz@rccd.cc.ca.us>
1 sibling, 0 replies; 3+ messages in thread
From: Areski Belaid @ 2002-04-25 17:18 UTC (permalink / raw)
To: pgsql-php; Julio Cuz, Jr. <jcuz@rccd.cc.ca.us>
Hi the Community,
A good exemple, it's always better that a long...
You must use the eval fonction. (www.php.net)
<?
$artist[]="Areski1";
$artist[]="Areski2";
$artist[]="Areski3";
$artist[]="Areski4";
$c0="Kiki1";
$c1="Kiki2";
$c2="Kiki3";
$c3="Kiki4";
for($count = 0; $count < sizeof($artist); $count++)
{
eval( "echo \$c$count.\"<br>\";" ); //just to see no important
eval( "\$c$count = \"$artist[$count]\";" );
eval( "echo \"-->\".\$c$count.\"<br><br>\";" );//just to see no important
}
?>
I have the following variables: $c1 thru $c10.
a.. 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.
a.. 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Variables
@ 2002-04-25 17:56 Kwabena Adowah Adu <kwab@lucidtechsolutions.com>
parent: Julio Cuz, Jr. <jcuz@rccd.cc.ca.us>
1 sibling, 0 replies; 3+ messages in thread
From: Kwabena Adowah Adu @ 2002-04-25 17:56 UTC (permalink / raw)
To: Julio Cuz, Jr. <jcuz@rccd.cc.ca.us>; +Cc: pgsql-php
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. <jcuz@rccd.cc.ca.us> [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 "<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
-------------------------------
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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2002-04-25 17:56 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-04-25 15:57 Variables Julio Cuz, Jr. <jcuz@rccd.cc.ca.us>
2002-04-25 17:18 ` Areski Belaid <areski5@hotmail.com>
2002-04-25 17:56 ` Kwabena Adowah Adu <kwab@lucidtechsolutions.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox