Re: Variables

From: Kwabena Adowah Adu <kwab(at)lucidtechsolutions(dot)com>
To: "Julio Cuz, Jr(dot)" <jcuz(at)rccd(dot)cc(dot)ca(dot)us>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: Variables
Date: 2002-04-25 17:56:33
Message-ID: 20020425175633.GA16549@seamus
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)rccd(dot)cc(dot)ca(dot)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(at)rccd(dot)cc(dot)ca(dot)us
-------------------------------
Kwabena Adowah Adu - Consultant
Lucid Tech Solutions, LLC
P.O. Box 135
Wallingford, PA 19086
Tel : 610.583.2737 | 484.444.0788
kwab(at)lucidtechsolutions(dot)com
http://www.lucidtechsolutions.com

In response to

  • Variables at 2002-04-25 15:57:31 from Julio Cuz, Jr.

Browse pgsql-php by date

  From Date Subject
Next Message angelo.rigo 2002-04-25 20:00:04 id field error
Previous Message Areski Belaid 2002-04-25 17:18:06 Re: Variables