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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
2번째 줄: 2번째 줄:
;PHP array_replace()
;PHP array_replace()


<source lang='PHP'>
<syntaxhighlight lang='PHP'>
$base = array("orange", "banana", "apple", "raspberry");
$base = array("orange", "banana", "apple", "raspberry");
$replacements = array(0 => "pineapple", 4 => "cherry");
$replacements = array(0 => "pineapple", 4 => "cherry");
17번째 줄: 17번째 줄:
#    [4] => cherry
#    [4] => cherry
# )
# )
</source>
</syntaxhighlight>
<source lang='PHP'>
<syntaxhighlight lang='PHP'>
$base = array("orange", "banana", "apple", "raspberry");
$base = array("orange", "banana", "apple", "raspberry");
$replacements = array(0 => "pineapple", 5 => "cherry");
$replacements = array(0 => "pineapple", 5 => "cherry");
31번째 줄: 31번째 줄:
#    [5] => cherry
#    [5] => cherry
# )
# )
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:34 판

1 개요

PHP array_replace()
$base = array("orange", "banana", "apple", "raspberry");
$replacements = array(0 => "pineapple", 4 => "cherry");
$replacements2 = array(0 => "grape");

$basket = array_replace($base, $replacements, $replacements2);
print_r($basket);
# Array
# (
#     [0] => grape
#     [1] => banana
#     [2] => apple
#     [3] => raspberry
#     [4] => cherry
# )
$base = array("orange", "banana", "apple", "raspberry");
$replacements = array(0 => "pineapple", 5 => "cherry");
$basket = array_replace($base, $replacements);
print_r($basket);
# Array
# (
#     [0] => pineapple
#     [1] => banana
#     [2] => apple
#     [3] => raspberry
#     [5] => cherry
# )

2 같이 보기

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