1veedo Posted December 25, 2004 Posted December 25, 2004 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? (This is going to be my filing system for a new game I'm working on: [x][y][info])
Dave Posted December 25, 2004 Posted December 25, 2004 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 ) );
Dave Posted December 25, 2004 Posted December 25, 2004 Co-incidentally, using arrays with indexes starting from 0 is much nicer on the eyes: $a = array( array(12, 77), array(11, 93) );
1veedo Posted December 25, 2004 Author Posted December 25, 2004 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now