RE: [PHP] variable hell
| From: | Mike Johnson | Date: | Tue, 04 Jan 2005 14:52:34 +0000 |
| Subject: | RE: [PHP] variable hell | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-205588@lists.php.net to get a copy of this message | ||
From: mario [mailto:developer@icop.gr]
> 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"
I'd imagine, at this point, you'd need to move into the realm of
associative arrays.
$x = 'products';
$issorttext[$x] = 150;
$isnewsorttext[$x] = 350;
$iscount[$x] = 50;
$isnewcount[$x] = 20;
After this, you'd end up with four arrays of one key each ('products'),
referenced as such:
echo $issorttext['products']; // echoes 150
Then do the same for the key 'offers' and you'd have the same four
arrays, but now each with two keys.
Hope this wasn't too confusing an explanation. :)
--
Mike Johnson Smarter Living, Inc.
Web Developer www.smarterliving.com
mike@smarterliving.com (617) 886-5539