"딕셔너리 리스트 컬럼 추출하여 리스트 만들기"의 두 판 사이의 차이

18번째 줄: 18번째 줄:
==PHP==
==PHP==
[[분류: PHP]]
[[분류: PHP]]
{{참고|딕셔너리 리스트 컬럼 추출하여 리스트 만들기}}
{{참고|PHP 딕셔너리 리스트 컬럼 추출하여 리스트 만들기}}
<source lang='php'>
<source lang='php'>
$members = [
$members = [

2020년 7월 11일 (토) 19:57 판

1 개요

딕셔너리 리스트 컬럼 추출하여 리스트 만들기

2 JavaScript

members = [
  { id: 102, name: 'Ashley Allen', address: 'Seoul' },
  { id: 202, name: 'Peter Parker', address: 'New York' },
  { id: 104, name: 'John Smith', address: 'Tokyo' }
]
console.log(members.map(x => x.address))
// [ 'Seoul', 'New York', 'Tokyo' ]

3 PHP

$members = [
    ['id'=>102, 'name'=>'Ashley Allen', 'address'=>'Seoul'],
    ['id'=>202, 'name'=>'Peter Parker', 'address'=>'New York'],
    ['id'=>104, 'name'=>'John Smith', 'address'=>'Tokyo'],
];
$addresses = array_map(function($x) { return $x['address']; }, $members);
print_r( $addresses );
# Array
# (
#     [0] => Seoul
#     [1] => New York
#     [2] => Tokyo
# )

4 Python

members = [
    {'id': 102, 'name': "Ashley Allen", 'address': "Seoul"},
    {'id': 202, 'name': "Peter Parker", 'address': "New York"},
    {'id': 104, 'name': "John Smith", 'address': "Tokyo"},
]
print(list(m['address'] for m in members))
## ['Seoul', 'New York', 'Tokyo']
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}