글쎄, 나는 참조가 무엇인지, 언제 사용되는지는 분명하다.참조로 전달 기능
실제로 얻을 수없는 한 가지는 참조로 함수를 전달하는 것이 더 나을 때입니다.
<?php
//right here, I wonder why and when
function &test(){
}
는
<?php
$numbers = array(2,3,4);
foreach ($numbers as &$number){
$number = $number * 2;
}
// now numbers is $numbers = array(4,6,8);
$var = 'test';
$foo = &var; //now all changes to $foo will be affected to $var, because we've assigned simple pointer
//Similar to array_push()
function add_key(&$array, $key){
return $array[$key];
}
//so we don't need to assign returned value from this function
//we just call this one
$array = array('a', 'b');
add_key($array,'c');
//now $array is ('a', 'b', 'c');
참조를 사용하는 모든 혜택
참조로 함수를 전달하는 "의 사용을 제외하고, 나에게 명백하다, 내가 참조를 이해하는 방법과 같은 몇 가지 예제가있어, 혼란을 피하기 위해 "질문 : 참조 기능을 통과 할 때 감사
이 질문은 http://programmers.stackexchange.com/에 속해 있습니다. – acme