Apps Creating MultiDimensional Arrays

redbrad0

Lurker
I am new to Java programming and trying to grasp it. I have done some searching, but I can't seem to find anything on creating an array the way I am used to with PHP. The only way to explain what I am looking for is showing it to you in PHP. Can someone help with a quick example that would do the same thing as the below PHP Code?

STORING DATA IN THE ARRAY
PHP:
$response = array();
    $response['InvitedFriends'] = array();
        $friend = array();
        $friend['ID'] = "1234";
        $friend['Name'] = "YourName";
        array_push($response['InvitedFriends'], $friend);
        
        $friend = array();
        $friend['ID'] = "4321";
        $friend['Name'] = "NameYour";
        array_push($response['InvitedFriends'], $friend);
    $response['TaggedFriends'] = array();
        $friend = array();
        $friend['ID'] = "1234";
        $friend['Name'] = "YourName";
        array_push($response['TaggedFriends'], $friend);
        
        $friend = array();
        $friend['ID'] = "4321";
        $friend['Name'] = "NameYour";
        array_push($response['TaggedFriends'], $friend);

LOOPING THROUGH EACH RECORD
PHP:
foreach ($response['InvitedFriends'] as $Invitedfriend)    {
    echo "FriendID:" . $InvitedFriend['ID'] . " FriendName:" . $InvitedFriend['Name'] . "<br>";
}
 

jonbonazza

Android Expert
You create multi-dimensional arrays in java like so:
Code:
int[][] arr;
arr = new int[5][8];

There is no foreach keyword in java, thus you are stuck using the standard for loop.
 
Top