"PHP array replace recursive()"의 두 판 사이의 차이

(새 문서: ;PHP array_replace_recursive() ==예시== <source lang='php'> $computer1 = array( 'owner' => 'John', 'softwares' => array( 'Windows', 'Office', 'Photoshop', 'Python', 'Apache' ),...)
 
잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 2명의 중간 판 5개는 보이지 않습니다)
1번째 줄: 1번째 줄:
;PHP array_replace_recursive()
;PHP array_replace_recursive()


==예시==
==예시 1==
<source lang='php'>
<syntaxhighlight lang='php'>
$base = array(
'citrus' => array("orange"),
'berries' => array("blackberry", "raspberry"),
);
$replacements = array(
'citrus' => array('pineapple'),
'berries' => array('blueberry')
);
$basket = array_replace_recursive($base, $replacements);
print_r($basket);
# Array
# (
#    [citrus] => Array
#        (
#            [0] => pineapple
#        )
#
#    [berries] => Array
#        (
#            [0] => blueberry
#            [1] => raspberry
#        )
#
# )
</syntaxhighlight>
 
==예시 2==
<syntaxhighlight lang='php'>
$base = array(
'citrus' => array("orange"),
'berries' => array("blackberry", "raspberry"),
'others' => 'banana'
);
$replacements = array(
'citrus' => 'pineapple',
'berries' => array('blueberry'),
'others' => array('litchis')
);
$replacements2 = array(
'citrus' => array('pineapple'),
'berries' => array('blueberry'),
'others' => 'litchis'
);
$basket = array_replace_recursive($base, $replacements, $replacements2);
print_r($basket);
# Array
# (
#    [citrus] => Array
#        (
#            [0] => pineapple
#        )
#
#    [berries] => Array
#        (
#            [0] => blueberry
#            [1] => raspberry
#        )
#
#    [others] => litchis
# )
</syntaxhighlight>
 
==예시 3==
<syntaxhighlight lang='php'>
$computer1 = array(
$computer1 = array(
'owner' => 'John',
'owner' => 'John',
64번째 줄: 128번째 줄:
#  
#  
# )
# )
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[PHP array_replace()]]
* [[PHP array_merge_recursive()]]
* [[array_replace_recursive()]]
* [[array_replace_recursive()]]
==참고==
* http://php.net/manual/kr/function.array-replace-recursive.php


[[분류: PHP]]
[[분류: PHP]]
[[분류: Array]]
[[분류: Array]]

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

PHP array_replace_recursive()

1 예시 1[ | ]

$base = array(
	'citrus' => array("orange"),
	'berries' => array("blackberry", "raspberry"),
);
$replacements = array(
	'citrus' => array('pineapple'),
	'berries' => array('blueberry')
);
$basket = array_replace_recursive($base, $replacements);
print_r($basket);
# Array
# (
#     [citrus] => Array
#         (
#             [0] => pineapple
#         )
# 
#     [berries] => Array
#         (
#             [0] => blueberry
#             [1] => raspberry
#         )
# 
# )

2 예시 2[ | ]

$base = array(
	'citrus' => array("orange"),
	'berries' => array("blackberry", "raspberry"),
	'others' => 'banana'
);
$replacements = array(
	'citrus' => 'pineapple',
	'berries' => array('blueberry'),
	'others' => array('litchis')
);
$replacements2 = array(
	'citrus' => array('pineapple'),
	'berries' => array('blueberry'),
	'others' => 'litchis'
);
$basket = array_replace_recursive($base, $replacements, $replacements2);
print_r($basket);
# Array
# (
#     [citrus] => Array
#         (
#             [0] => pineapple
#         )
# 
#     [berries] => Array
#         (
#             [0] => blueberry
#             [1] => raspberry
#         )
# 
#     [others] => litchis
# )

3 예시 3[ | ]

$computer1 = array(
	'owner' => 'John',
	'softwares' => array( 'Windows', 'Office', 'Photoshop', 'Python', 'Apache' ),
	'peripherals' => array(
		'keyboard' => 'Samsung',
	)
);

$computer2 = array(
	'owner' => 'Jane',
	'softwares' => array( 'Linux', 'Apache', 'MySQL', 'PHP' ),
	'peripherals' => array(
		'keyboard' => 'LG',
		'mouser' => 'LG',
	)
);

$merged1 = array_replace_recursive($computer1, $computer2);
$merged2 = array_replace_recursive($computer2, $computer1);

print_r( $merged1 );
# Array
# (
#     [owner] => Jane
#     [softwares] => Array
#         (
#             [0] => Linux
#             [1] => Apache
#             [2] => MySQL
#             [3] => PHP
#             [4] => Apache
#         )
# 
#     [peripherals] => Array
#         (
#             [keyboard] => LG
#             [mouser] => LG
#         )
# 
# )

print_r( $merged2 );
# Array
# (
#     [owner] => John
#     [softwares] => Array
#         (
#             [0] => Windows
#             [1] => Office
#             [2] => Photoshop
#             [3] => Python
#             [4] => Apache
#         )
# 
#     [peripherals] => Array
#         (
#             [keyboard] => Samsung
#             [mouser] => LG
#         )
# 
# )

4 같이 보기[ | ]

5 참고[ | ]

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