Re: Variable Syntax Help Needed PLEASE!!
| From: | Marco Roccioletti | Date: | Mon, 13 Nov 2000 08:52:25 +0000 |
| Subject: | Re: Variable Syntax Help Needed PLEASE!! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24932@lists.php.net to get a copy of this message | ||
On Mon, 13 Nov 2000, Jeff Lacy wrote:
>
> Hello everybody,
>
> I have a hopefully simple question. Assume I have an array like so:
>
> $i1[0] = "blah";
> $i1[1] = "barf";
> $i2[0] = "hello";
> $i2[1] = "there";
> $i3[0] = "good";
> $i3[1] = "afternoon";
> .....
>
>
> $x is the number of arrays above, or in this case 3. I also have a for loop like:
>
> for ($a = "1"; $a <= $x; $a++) {
> ....
> }}
>
>
> How would I refer to $i1[0] and $i1[1] and $i2[0] and $i2[1] and $i3[0] and $i3[1] in my for
> loop? Thanks in advance :-D
>
> Jeff
>
Why don't you use a two-dimensional array like this:
$i[1][0] = "blah";
$i[1][1] = "barf";
$i[2][0] = "hello";
$i[2][1] = "there";
$i[3][0] = "good";
$i[3][1] = "afternoon";
If you don't want to do it that way, you can do:
for ($a = 1; $a <= $x; $a++) {
// reference your arrays:
echo ${"i" . $a}[0]; // same as "echo $i1[0];" when $a=1
echo ${"i" . $a}[1];
}
Cheers,
Marco