"함수 array merge()"의 두 판 사이의 차이

8번째 줄: 8번째 줄:
ARR1=("John Smith" "Jane Doe")
ARR1=("John Smith" "Jane Doe")
ARR2=("Mike Barnes" "Kevin Patterson")
ARR2=("Mike Barnes" "Kevin Patterson")
MERGED=("${ARR1[@]}")
MERGED=("${ARR1[@]}" "${ARR2[@]}")
MERGED+=("${ARR2[@]}")
for VALUE in "${MERGED[@]}"; do echo "[$VALUE]"; done
for VALUE in "${MERGED[@]}"; do echo "[$VALUE]"; done
# [John Smith]
# [John Smith]
15번째 줄: 14번째 줄:
# [Mike Barnes]
# [Mike Barnes]
# [Kevin Patterson]
# [Kevin Patterson]
</source>
<source lang='Bash'>
ARR1=("John Smith" "Jane Doe")
ARR2=("Mike Barnes" "Kevin Patterson")
MERGED=("${ARR1[@]}")
MERGED+=("${ARR2[@]}")
for VALUE in "${MERGED[@]}"; do echo "[$VALUE]"; done
</source>
</source>



2014년 5월 29일 (목) 00:48 판

array_merge
+

1 Bash

ARR1=("John Smith" "Jane Doe")
ARR2=("Mike Barnes" "Kevin Patterson")
MERGED=("${ARR1[@]}" "${ARR2[@]}")
for VALUE in "${MERGED[@]}"; do echo "[$VALUE]"; done
# [John Smith]
# [Jane Doe]
# [Mike Barnes]
# [Kevin Patterson]
ARR1=("John Smith" "Jane Doe")
ARR2=("Mike Barnes" "Kevin Patterson")
MERGED=("${ARR1[@]}")
MERGED+=("${ARR2[@]}")
for VALUE in "${MERGED[@]}"; do echo "[$VALUE]"; done

2 PHP

$arr1 = array('a', 'b');
$arr2 = array('c', 'd');
$merged = array_merge($arr1, $arr2);
print_r($merged);
// Array
// (
//     [0] => a
//     [1] => b
//     [2] => c
//     [3] => d
// )

3 Python

arr1 = ['a', 'b']
arr2 = ['c', 'd']
merge = arr1 + arr2
print merge
# ['a', 'b', 'c', 'd']

4 같이 보기

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