[PHP] variable hell
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 Thanks in advance Mario -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] variable hell
From: mario [mailto:[EMAIL PROTECTED] 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 Developerwww.smarterliving.com [EMAIL PROTECTED] (617) 886-5539 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable hell
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-OC|8-/C|:-( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable hell
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 Thanks in advance Mario You probably want to look into arrays... http://us4.php.net/manual/en/language.types.array.php http://us4.php.net/array -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable hell
On Tue, 2005-01-04 at 16:54 +0200, 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 Thanks in advance Mario This seems like an odd approach to doing this.. but here goes: $isproducttext = 120; $x = product; $y = is . $x . text; print $$y; -- /*** * Robby Russell | Owner.Developer.Geek * PLANET ARGON | www.planetargon.com * Portland, OR | [EMAIL PROTECTED] * 503.351.4730 | blog.planetargon.com * PHP/PostgreSQL Hosting Development *--- Now supporting PHP5 --- / -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php