"Array replace recursive()"의 두 판 사이의 차이

(새 문서: category: Array ;array_replace_recursive() ==PHP== category: PHP <source lang='php'> <?php $computer1 = array( 'owner' => 'John', 'softwares' => array( 'Windows', 'Office',...)
 
71번째 줄: 71번째 줄:
==같이 보기==
==같이 보기==
*[[array_merge_recursive()]]
*[[array_merge_recursive()]]
*[[array_replace()]]

2016년 1월 29일 (금) 15:02 판

array_replace_recursive()

1 PHP

<?php
$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
#         )
# 
# )

2 같이 보기

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