Forum Moderators: coopster

Message Too Old, No Replies

PHP 2D arrays

         

smagdy

7:56 pm on Feb 16, 2005 (gmt 0)

10+ Year Member



Hi all..

Please how do we create 2D array and make it global in PHP.

thanks in advance

hakre

12:54 am on Feb 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you can create 2D arrays in php by combining 2 or more arrays together:

$arr2d = array(1=>array(2=>'1,2'));

so

$arr2d[1][2]
is 1,2 then. it should be possible to use
$arr2d[2][1] = 'test';
to set values of the array.

this array is automatically global. only if you make this in a function it's not. check variable scope in the php docs for more info.

coopster

3:56 am on Feb 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hakre is spot on. And PHP has a lot of nice features when it comes to multi-dimensional arrays [php.net].