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.
Convert Java Array
Moderator: General Moderators
Re: Convert Java Array
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:
You could also specify key names:
Code: Select all
int array[][] = new int[3][3]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));Code: Select all
$arrayName = array(
'key1' => array(1, 2, 3),
'key2' => array(4, 5, 6),
'key3' => array(7, 8, 9)
);