Jump to content

Recommended Posts

Posted

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])

Posted

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 )
);

Posted

Co-incidentally, using arrays with indexes starting from 0 is much nicer on the eyes:

 

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

Posted

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

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.