大家好!數組:如何返回參考/指針
如何返回函數中的數組引用/指針?
例如:
$a=array('given'=>array());
function getRef(&$ref){
//adds a child element to the given reference/pointer
$ref['test']=array();
//doesn't return the current reference/pointer
return $ref['test'];
}
//out: Array ([given] => Array ([test] => Array ()))
$p=getRef($a['given']);
print_r($a);
//out: same as above
//expected: ([given] => Array ([test] => Array ([test2] => Array ())))
$p['test2']=array();
print_r($a);
謝謝!
檢查下面的工作:) – Gogul