在通过引用调用PHP的情况下, 如果在函数内部修改了实际值, 则实际值将被修改。在这种情况下, 你需要将&(&)符号与形式参数一起使用。 &代表变量的引用。
让我们借助示例来了解通过引用进行调用的概念。
例子1
在此示例中, 变量$ str被传递到加法器函数, 在此它与”按引用调用”字符串连接在一起。在这里, 打印$ str变量结果为’This is Call By Reference’。这是因为更改是在实际变量$ str中完成的。
<?php
function adder(&$str2)
{
$str2 .= 'Call By Reference';
}
$str = 'This is ';
adder($str);
echo $str;
?>
输出
This is Call By Reference
例子2
让我们通过另一个示例了解通过引用概念进行的PHP调用。
<?php
function increment(&$i)
{
$i++;
}
$i = 10;
increment($i);
echo $i;
?>
输出
11
来源:
https://www.srcmini02.com/29149.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_38060.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57