2D array

(2d array에서 넘어옴)
2d array

1 Bash[ | ]

declare -A MEMBERS=(
[0,ID]=102 [0,Name]="Yonezawa Akinori" [0,Address]="Naha, Okinawa"
[1,ID]=202 [1,Name]="Murata Makoto" [1,Address]="Sendai, Miyagi"
[2,ID]=104 [2,Name]="Sakamura Ken" [2,Address]="Kumamoto, Kumamoto"
)

echo ${MEMBERS[0,ID]}
echo ${MEMBERS[0,Name]}
echo ${MEMBERS[0,Address]}
echo ${MEMBERS[1,ID]}
echo ${MEMBERS[2,ID]}
# 102
# Yonezawa Akinori
# Naha, Okinawa
# 202
# 104
declare -A MEMBERS
declare -A r0=([ID]=102 [Name]="Yonezawa Akinori" [Address]="Naha, Okinawa")
declare -A r1=([ID]=202 [Name]="Murata Makoto" [Address]="Sendai, Miyagi")
declare -A r2=([ID]=104 [Name]="Sakamura Ken" [Address]="Kumamoto, Kumamoto")

for i in {0..2}; do for c in ID Name Address; do
	ref="r$i[$c]"; MEMBERS[$i,$c]=${!ref}
done; done

echo ${MEMBERS[0,ID]}
echo ${MEMBERS[0,Name]}
echo ${MEMBERS[0,Address]}
echo ${MEMBERS[1,ID]}
echo ${MEMBERS[2,ID]}
# 102
# Yonezawa Akinori
# Naha, Okinawa
# 202
# 104
declare -A MEMBER0=([ID]=102 [Name]="Yonezawa Akinori" [Address]="Naha, Okinawa")
declare -A MEMBER1=([ID]=202 [Name]="Murata Makoto" [Address]="Sendai, Miyagi")
declare -A MEMBER2=([ID]=104 [Name]="Sakamura Ken" [Address]="Kumamoto, Kumamoto")

for i in {0..2}; do for c in ID Name Address; do
	ref="MEMBER$i[$c]"; echo "$ref = ${!ref}";
done; done
# MEMBER0[ID] = 102
# MEMBER0[Name] = Yonezawa Akinori
# MEMBER0[Address] = Naha, Okinawa
# MEMBER1[ID] = 202
# MEMBER1[Name] = Murata Makoto
# MEMBER1[Address] = Sendai, Miyagi
# MEMBER2[ID] = 104
# MEMBER2[Name] = Sakamura Ken
# MEMBER2[Address] = Kumamoto, Kumamoto

echo ${MEMBER1[Name]}
# Murata Makoto

2 Go[ | ]

package main

import "fmt"

func main() {
    var members []interface{}
    members = append(members,
        map[string]interface{}{"ID":102, "Name":"Yonezawa Akinori", "Address":"Naha, Okinawa"     },
        map[string]interface{}{"ID":202, "Name":"Murata Makoto"   , "Address":"Sendai, Miyagi"    },
        map[string]interface{}{"ID":104, "Name":"Sakamura Ken"    , "Address":"Kumamoto, Kumamoto"},
    )
	for k, v := range members {
		fmt.Println(k, v)
	}
}

3 Java[ | ]

ArrayList<Object> list = new ArrayList<Object>();
list.add(new ArrayList<Object>(Arrays.asList("102", "Yonezawa Akinori", "Naha, Okinawa")));
list.add(new ArrayList<Object>(Arrays.asList("202", "Murata Makoto", "Sendai, Miyagi")));
list.add(new ArrayList<Object>(Arrays.asList("104", "Sakamura Ken", "Kumamoto, Kumamoto")));
System.out.print(list.toString());
/*
[[102, Yonezawa Akinori, Naha, Okinawa], [202, Murata Makoto, Sendai, Miyagi], [104, Sakamura Ken, Kumamoto, Kumamoto]]
*/
ArrayList<Object> list = new ArrayList<Object>(Arrays.asList((Object)
  new ArrayList<Object>(Arrays.asList("102", "Yonezawa Akinori", "Naha, Okinawa")),
  new ArrayList<Object>(Arrays.asList("202", "Murata Makoto", "Sendai, Miyagi")),
  new ArrayList<Object>(Arrays.asList("104", "Sakamura Ken", "Kumamoto, Kumamoto"))
));
System.out.print(list.toString());
/*
[[102, Yonezawa Akinori, Naha, Okinawa], [202, Murata Makoto, Sendai, Miyagi], [104, Sakamura Ken, Kumamoto, Kumamoto]]
*/

4 JavaScript[ | ]

var arr = [[1,2], [3,4], [5,6]];
var rows = [
	["102", "Yonezawa Akinori", "Naha, Okinawa"],
	["202", "Murata Makoto", "Sendai, Miyagi"],
	["104", "Sakamura Ken", "Kumamoto, Kumamoto"]
];
for(i in rows) console.log(rows[i].toString());
// 102,Yonezawa Akinori,Naha, Okinawa
// 202,Murata Makoto,Sendai, Miyagi
// 104,Sakamura Ken,Kumamoto, Kumamoto
var rows = new Array();
rows.push( ["102", "Yonezawa Akinori", "Naha, Okinawa"] );
rows.push( ["202", "Murata Makoto", "Sendai, Miyagi"] );
rows.push( ["104", "Sakamura Ken", "Kumamoto, Kumamoto"] );
for(i in rows) console.log(rows[i].toString());

5 PHP[ | ]

$arr = [
  ["102", "Yonezawa Akinori", "Naha, Okinawa"],
  ["202", "Murata Makoto", "Sendai, Miyagi"],
  ["104", "Sakamura Ken", "Kumamoto, Kumamoto"],
];
print_r($arr);
# Array
# (
#     [0] => Array
#         (
#             [0] => 102
#             [1] => Yonezawa Akinori
#             [2] => Naha, Okinawa
#         )
#     [1] => Array
#         (
#             [0] => 202
#             [1] => Murata Makoto
#             [2] => Sendai, Miyagi
#         )
#     [2] => Array
#         (
#             [0] => 104
#             [1] => Sakamura Ken
#             [2] => Kumamoto, Kumamoto
#         )
# )

6 Python[ | ]

arr = [
  ["102", "Yonezawa Akinori", "Naha, Okinawa"],
  ["202", "Murata Makoto", "Sendai, Miyagi"],
  ["104", "Sakamura Ken", "Kumamoto, Kumamoto"]
]
print(arr)
# [['102', 'Yonezawa Akinori', 'Naha, Okinawa'], ['202', 'Murata Makoto', 'Sendai, Miyagi'], ['104', 'Sakamura Ken', 'Kumamoto, Kumamoto']]
import pprint
arr = [
  ["102", "Yonezawa Akinori", "Naha, Okinawa"],
  ["202", "Murata Makoto", "Sendai, Miyagi"],
  ["104", "Sakamura Ken", "Kumamoto, Kumamoto"]
]
pprint.pprint(arr)
# [['102', 'Yonezawa Akinori', 'Naha, Okinawa'],
#  ['202', 'Murata Makoto', 'Sendai, Miyagi'],
#  ['104', 'Sakamura Ken', 'Kumamoto, Kumamoto']]

7 Ruby[ | ]

arr = [
  ["102", "Yonezawa Akinori", "Naha, Okinawa"],
  ["202", "Murata Makoto", "Sendai, Miyagi"],
  ["104", "Sakamura Ken", "Kumamoto, Kumamoto"]
]
print arr
# [["102", "Yonezawa Akinori", "Naha, Okinawa"], ["202", "Murata Makoto", "Sendai, Miyagi"], ["104", "Sakamura Ken", "Kumamoto, Kumamoto"]]

8 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}