Page 1 of 1

2D Array OF Arrays

Posted: Mon Oct 13, 2008 1:00 am
by 3hhh
Hi,

I would like to store and print a 2D array of arrays. For example,

seats[0] = "A1,A2,A3";
seats[1] = "B1,B2,B3";

then I have:

$testArray[0]['seats'] = $seats[0];
$testArray[1]['seats'] = $seats[1];

Now, I want to print $testArray with the values of the index and the values of $seats. How can I do that? For example, I want to display:

0 A1 A2 A3
1 B1 B2 B3

Thank you in advance! :)

Re: 2D Array OF Arrays

Posted: Mon Oct 13, 2008 1:25 am
by PietM
Like this?

Code: Select all

$seats[0] = array('A1','A2','A3');
$seats[1] = array('B1','B2','B3');
 
print join(',',$seats[0]);
print join(',',$seats[1]);
 

Re: 2D Array OF Arrays

Posted: Mon Oct 13, 2008 3:52 am
by 3hhh
Sorry, my mistake.

seats[0] = "a1";
seats[1] = "a2";

$testArray[0]['seats'] = $seats;

I want to print $testArray with the values of the index and the values of $seats(which is an ARRAY itself).

So I would like to display:

0 a1 a2

Thanks in advance!

Re: 2D Array OF Arrays

Posted: Mon Oct 13, 2008 4:04 am
by PietM

Code: Select all

for ($i = 0; $i < count($testArray); $i++) {
    print $i . ': ' . join(',',$testArray[$i]['seats']);
  }
 

Re: 2D Array OF Arrays

Posted: Mon Oct 13, 2008 8:32 am
by 3hhh
PietM wrote:

Code: Select all

for ($i = 0; $i < count($testArray); $i++) {
    print $i . ': ' . join(',',$testArray[$i]['seats']);
  }
 
Hey PietM, thank you sooooo much! :)