PHP通過引用傳遞參數


<?php
function add_some_extra(&$string) // 引入變量,使用同一個存儲地址
{
    $string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str;    // outputs 'This is a string, and something extra.'
?> 

輸出:
This is a string, and something extra.

如果沒有這個&符號,

<?php
function add_some_extra($string) 
{
    $string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str;    // outputs 'This is a string, '
?> 

輸出:
This is a string,


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM