Re: variable hell
| From: | Jyry Kuukkanen | Date: | Tue, 04 Jan 2005 14:55:08 +0000 |
| Subject: | Re: variable hell | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-205589@lists.php.net to get a copy of this message | ||
On Tue, 4 Jan 2005, mario wrote:
> Hi all
>
> I have few variables in this format:
>
> $isproductssorttext = "150";
> $isofferssorttext = "250";
> $isnewproductssorttext = "350";
>
> $isproductscount = "50";
> $isofferscount = "30";
> $isnewproductscount = "20";
> etc....
>
>
> What I want to do is have a variable
> e.g. $x = "products";
>
> and create from that, the variable $is'products'sorttext
> (<--$isproductssorttext) and use its value
>
> so if $x was "offers" on echo I would have (250) <-- "$isofferssorttext"
> if $x was newproducts on echo I would have (350) <--
> "$isnewproductssorttext"
Hello
I believe what you are after is ${'is'.$x.'sorttext'}
but I would rather use the nfollowing approach as it is much more readable
and easier to debug:
$issorttext = array('offers' = 250, 'newproducts' => 250, ...)
and then use it:
echo $issorttext['offers'];
--
Cheers,
--Jyry
C|:-( C|:-/ C|========8-O C|8-/ C|:-(