Page 1 of 1
Convert Java Array
Posted: Mon Oct 03, 2011 9:56 am
by alvinmeister
int array[][] ={{1,2,3},{4,5,6},{7,8,9}};
int array1[][] ={{1,2,3},{4,5,6},{7,8,9}};
int array2[][] = new int[3][3];
new to php.
thanks in advance.
Re: Convert Java Array
Posted: Mon Oct 03, 2011 10:12 am
by Celauran
Unlike Java, you don't explicitly define array sizes in PHP.
is, therefore, unnecessary. PHP is also weakly typed, so specifying that the array will contain ints is equally unnecessary. Moreover, arrays in PHP are not restricted to a single type.
Your first two arrays look the same to me, and can be written thus:
Code: Select all
$arrayName = array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9));
You could also specify key names:
Code: Select all
$arrayName = array(
'key1' => array(1, 2, 3),
'key2' => array(4, 5, 6),
'key3' => array(7, 8, 9)
);