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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
6번째 줄: 6번째 줄:
[[분류: PHP]]
[[분류: PHP]]
{{참고|PHP array_column()}}
{{참고|PHP array_column()}}
<syntaxhighlight lang='php'>
<syntaxhighlight lang='php' run>
$orders = [
$orders = [
   ['id'=>1, 'name'=>'Ashley', 'date'=>'2020-05-20'],
   ['id'=>1, 'name'=>'Ashley', 'date'=>'2020-05-20'],

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 }}