"함수 column()"의 두 판 사이의 차이

 
(사용자 2명의 중간 판 3개는 보이지 않습니다)
4번째 줄: 4번째 줄:


==PHP==
==PHP==
[[분류: PHP]]
{{참고|PHP array_column()}}
{{참고|PHP array_column()}}
<source lang='php'>
<syntaxhighlight lang='php' run>
$orders = [
$orders = [
   ['id'=>1, 'name'=>'Ashley', 'date'=>'2020-05-20'],
   ['id'=>1, 'name'=>'Ashley', 'date'=>'2020-05-20'],
15번째 줄: 16번째 줄:
$names = array_column($orders, 'name');
$names = array_column($orders, 'name');
print_r( $names );
print_r( $names );
</source>
</syntaxhighlight>


==Python==
==Python==
[[분류: Python]]
{{참고|파이썬 column()}}
{{참고|파이썬 column()}}
<source lang='python'>
<syntaxhighlight lang='python' run>
orders = [
orders = [
   {'id': 1, 'name': 'Ashley', 'date': '2020-05-20'},
   {'id': 1, 'name': 'Ashley', 'date': '2020-05-20'},
28번째 줄: 30번째 줄:
]
]
names = [x['name'] for x in orders]
names = [x['name'] for x in orders]
print( names )
print( names ) # ['Ashley', 'Peter', 'Ashley', 'John', 'Peter']
# ['Ashley', 'Peter', 'Ashley', 'John', 'Peter']
</syntaxhighlight>
</source>

2021년 5월 1일 (토) 22:29 기준 최신판

1 개요[ | ]

함수 column()
함수 array_column()

2 PHP[ | ]

$orders = [
  ['id'=>1, 'name'=>'Ashley', 'date'=>'2020-05-20'],
  ['id'=>2, 'name'=>'Peter' , 'date'=>'2020-05-20'],
  ['id'=>3, 'name'=>'Ashley', 'date'=>'2020-05-05'],
  ['id'=>4, 'name'=>'John'  , 'date'=>'2020-05-05'],
  ['id'=>5, 'name'=>'Peter' , 'date'=>'2020-05-05'],
];
$names = array_column($orders, 'name');
print_r( $names );

3 Python[ | ]

orders = [
  {'id': 1, 'name': 'Ashley', 'date': '2020-05-20'},
  {'id': 2, 'name': 'Peter' , 'date': '2020-05-20'},
  {'id': 3, 'name': 'Ashley', 'date': '2020-05-05'},
  {'id': 4, 'name': 'John'  , 'date': '2020-05-05'},
  {'id': 5, 'name': 'Peter' , 'date': '2020-05-05'},
]
names = [x['name'] for x in orders]
print( names ) # ['Ashley', 'Peter', 'Ashley', 'John', 'Peter']
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}