RE: [PHP] Confusing array question ...
| From: | Martin Towell | Date: | Tue, 10 Sep 2002 23:51:24 +0000 |
| Subject: | RE: [PHP] Confusing array question ... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-115910@lists.php.net to get a copy of this message | ||
Try adding curly braces around the var name, like this:
for($i=0; $i<count(${"beginning" . $value . "end"}); $i++) {
also, a look at the variable variables manual page will help further
HTH
Martin
-----Original Message-----
From: John Kelly [mailto:johnkelly@hotmail.com]
Sent: Wednesday, September 11, 2002 9:27 AM
To: php-general@lists.php.net
Subject: [PHP] Confusing array question ...
Hi, I have 1 primary array called $item containing 20 values each of whose
value is part of the name of 20 other arrays containing various number of
values. How can I cycle through the primary $item array using a foreach and
within that do a for on each of the 20 secondary arrays dynamically
inserting each of the 20 secondary array names based on the value of the
current primary $item array. Something like the following which obviously
does not work.
<?php
foreach($item as $value) {
// do some stuff
for($i=0; $i<count($"beginning_of_array_name_always_the_same" . $value .
"end_of_array_name_always_the_same"); $i++) {
// do some stuff
}
}
?>
I am trying to avoid doing something like the following ...
<?php
foreach($item as $value) {
// do some stuff
if($value == 'red'){
$array = $temp_red_file;
} elseif ($value == 'green'){
$array = $temp_green_file;
// and so on for all 20 possibilities
}
for($i=0; $i<count($array); $i++) {
// do some stuff
}
}
?>
Thanks!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php