Re: Is their a function for this?

From: Date: Thu, 05 Apr 2001 08:57:49 +0000
Subject: Re: Is their a function for this?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-47212@lists.php.net to get a copy of this message
"Black S." wrote: > > Basically I have array variables, lets say: > ------------------------------------------- > $folder[0] = "basic"; > $folder[1] = "standard"; > $folder[2] = "knowledge"; > > Fruther down in the code: > ------------------------------------------- > $totalsub_basic = "10"; > $totalsub_standard = "24"; > $totalsub_knowledge = "12"; > > Everything runs fine until "$total_count" how do I take the value of > $folder[$i], lets say "standard" append that to "totalsub" and get the > value > of "$totalsub_standard"????? > ------------------------------------------- > $i = 0; > while($i < $level_0_links) { > echo "First While Loop"; > > if (ereg("^/$folder[$i]?", $PHP_SELF)) { > $a = 0; > $total_count = (eval("$totalsub_$folder[$i]")); <------- > while ($a < $total_count) { > echo "$a"; > $i++; > } > } > > $i++; > } > > Thanks Everyone! > Why not use some hash io separate variables? And, eh, why do you quote integer values? What I would suggest is something like this: /* Just as you already had.... */ $folder[0] = "basic"; $folder[1] = "standard"; $folder[2] = "knowledge"; /* -- HASH -- */ $totalsub{"basic"} = 10; $totalsub{"standard"} = 24; $totalsub{"knowledge"} = 12; In this way it's easy to access the totalsub-values: e.g.: $totalsub{$folder[0]} -- * R&zE: *************************** ** Renze Munnik ** ** E: renze@datalink.nl ** M: +31 6 218 111 43 ***************************

« previous php.general (#47212) next »