2D Array OF Arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
3hhh
Forum Newbie
Posts: 22
Joined: Wed Sep 10, 2008 12:02 pm

2D Array OF Arrays

Post 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! :)
PietM
Forum Newbie
Posts: 8
Joined: Mon Oct 06, 2008 2:56 am

Re: 2D Array OF Arrays

Post 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]);
 
3hhh
Forum Newbie
Posts: 22
Joined: Wed Sep 10, 2008 12:02 pm

Re: 2D Array OF Arrays

Post 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!
PietM
Forum Newbie
Posts: 8
Joined: Mon Oct 06, 2008 2:56 am

Re: 2D Array OF Arrays

Post by PietM »

Code: Select all

for ($i = 0; $i < count($testArray); $i++) {
    print $i . ': ' . join(',',$testArray[$i]['seats']);
  }
 
3hhh
Forum Newbie
Posts: 22
Joined: Wed Sep 10, 2008 12:02 pm

Re: 2D Array OF Arrays

Post 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! :)
Post Reply