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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 2명의 중간 판 7개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[분류: Array]]
[[분류: Array]]
{{다른뜻|concat()}}
{{다른뜻|concat()}}
{{다른뜻|SQL MERGE}}
;array_merge
;array_merge
;array concat
;concat
;concat
;+
;+
7번째 줄: 9번째 줄:
==Bash==
==Bash==
[[category: Bash]]
[[category: Bash]]
<source lang='Bash'>
<syntaxhighlight lang='Bash'>
ARR1=("John Smith" "Jane Doe")
ARR1=("John Smith" "Jane Doe")
ARR2=("Mike Barnes" "Kevin Patterson")
ARR2=("Mike Barnes" "Kevin Patterson")
16번째 줄: 18번째 줄:
# [Mike Barnes]
# [Mike Barnes]
# [Kevin Patterson]
# [Kevin Patterson]
</source>
</syntaxhighlight>
<source lang='Bash'>
<syntaxhighlight lang='Bash'>
ARR1=("John Smith" "Jane Doe")
ARR1=("John Smith" "Jane Doe")
ARR2=("Mike Barnes" "Kevin Patterson")
ARR2=("Mike Barnes" "Kevin Patterson")
23번째 줄: 25번째 줄:
MERGED+=("${ARR2[@]}")
MERGED+=("${ARR2[@]}")
for VALUE in "${MERGED[@]}"; do echo "[$VALUE]"; done
for VALUE in "${MERGED[@]}"; do echo "[$VALUE]"; done
</source>
</syntaxhighlight>


==JavaScript==
==JavaScript==
[[category: JavaScript]]
[[category: JavaScript]]
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript'>
var arr1 = ['a', 'b'];
var arr1 = ['a', 'b'];
var arr2 = ['c', 'd', 'e'];
var arr2 = ['c', 'd', 'e'];
36번째 줄: 38번째 줄:
console.log( merged );
console.log( merged );
// ["a", "b", "c", "d", "e"]
// ["a", "b", "c", "d", "e"]
</source>
</syntaxhighlight>
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript'>
var arr1 = ['a', 'b'];
var arr1 = ['a', 'b'];
var arr2 = ['c', 'd', 'e'];
var arr2 = ['c', 'd', 'e'];
43번째 줄: 45번째 줄:
console.log( arr1 );
console.log( arr1 );
// ["a", "b", "c", "d", "e"]
// ["a", "b", "c", "d", "e"]
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='PHP'>
<syntaxhighlight lang='PHP'>
$arr1 = array('a', 'b');
$arr1 = array('a', 'b');
$arr2 = array('c', 'd');
$arr2 = array('c', 'd');
59번째 줄: 61번째 줄:
//    [3] => d
//    [3] => d
// )
// )
</source>
</syntaxhighlight>


==Python==
==Python==
[[category: Python]]
[[category: Python]]
<source lang='Python'>
<syntaxhighlight lang='Python'>
a = ['Apple', 'Banana']
a = ['Apple', 'Banana']
b = ['Cranberry', 'Pear']
b = ['Cranberry', 'Pear']
69번째 줄: 71번째 줄:
print( c )
print( c )
# ['Apple', 'Banana', 'Cranberry', 'Pear']
# ['Apple', 'Banana', 'Cranberry', 'Pear']
</source>
</syntaxhighlight>
 
==Perl==
[[category: Perl]]
<syntaxhighlight lang='perl'>
my @a = ('Apple', 'Banana');
my @b = ('Cranberry', 'Pear');
my @c = (@a, @b);
print @c;
#AppleBananaCranberryPear
</syntaxhighlight>
 
==Ruby==
[[category: Ruby]]
<syntaxhighlight lang='ruby'>
a = ['Apple', 'Banana']
b = ['Cranberry', 'Pear']
c = a + b
puts c
# Apple
# Banana
# Cranberry
# Pear
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[array_push]]
*[[array_push]]
*[[array_replace()]]
*[[print_r]]
*[[print_r]]
*[[union]]
*[[union]]

2020년 11월 2일 (월) 02:32 기준 최신판

  다른 뜻에 대해서는 concat() 문서를 참조하십시오.
  다른 뜻에 대해서는 SQL MERGE 문서를 참조하십시오.
array_merge
array concat
concat
+

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 JavaScript[ | ]

var arr1 = ['a', 'b'];
var arr2 = ['c', 'd', 'e'];
var merged = arr1.concat(arr2);

console.log( arr1 );
// ["a", "b"]
console.log( merged );
// ["a", "b", "c", "d", "e"]
var arr1 = ['a', 'b'];
var arr2 = ['c', 'd', 'e'];
Array.prototype.push.apply(arr1, arr2);
console.log( arr1 );
// ["a", "b", "c", "d", "e"]

3 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
// )

4 Python[ | ]

a = ['Apple', 'Banana']
b = ['Cranberry', 'Pear']
c = a + b
print( c )
# ['Apple', 'Banana', 'Cranberry', 'Pear']

5 Perl[ | ]

my @a = ('Apple', 'Banana');
my @b = ('Cranberry', 'Pear');
my @c = (@a, @b);
print @c;
#AppleBananaCranberryPear

6 Ruby[ | ]

a = ['Apple', 'Banana']
b = ['Cranberry', 'Pear']
c = a + b
puts c
# Apple
# Banana
# Cranberry
# Pear

7 같이 보기[ | ]

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