Jump to content

3D array in PHP

Featured Replies

Quick question. I'm trying to make a 3D array in the sort of:

array(
1 => (1, 1),
2 => (1, 1)
);

type of way. I inductively assumed the following would work but I get a "parse error, unexpected T_DOUBLE_ARROW":

<?php
$tt = array(
1 => (1 => (0, 0, 0), 2 => (0, 0, 0), 3 => (0, 0, 0)),
2 => (1 => (0, 0, 0), 2 => (0, 0, 0), 3 => (0, 0, 0)),
3 => (1 => (0, 0, 0), 2 => (0, 0, 0), 3 => (0, 0, 0))
);
?>

So obviously the above is wrong but my good friend google doesn't seem to have a better way. So, anybody know how? :D

 

(This is going to be my filing system for a new game I'm working on: [x][y][info])

When you define arrays inside arrays, you need to call the array function.

 

For example for the simple array $a[0][0] to $a[1][1]...

 

$a = array(
       0 => array( 0 => 12, 1 => 77 ),
       1 => array( 0 => 11, 1 => 93 )
);

  • Author

Cool, thanks alot. For some reason it didnt require the other array() for my 2D one.

$tt = array(
0 => array(0 => array(0, 0, 0), 1 => array(0, 0, 0), 2 => array(0, 0, 0)),
1 => array(0 => array(0, 0, 0), 1 => array(0, 0, 0), 2 => array(0, 0, 0)),
2 => array(0 => array(0, 0, 0), 1 => array(0, 0, 0), 2 => array(0, 0, 0)));

I didn't realize I was starting on 1 until now.

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.