PHP按值调用

PHP允许你通过值调用函数并引用两者。在PHP中按值调用的情况下, 如果在函数内部修改了实际值, 则不会对其进行修改。

让我们借助示例来理解按值调用的概念。

例子1

在此示例中, 变量$ str被传递到加法器函数, 在此它与”按值调用”字符串连接在一起。但是, 打印$ str变量只会导致” Hello”。这是因为仅在局部变量$ str2中进行了更改。它不会反映到$ str变量。

<?php
function adder($str2)
{
    $str2 .= 'Call By Value';
}
$str = 'Hello ';
adder($str);
echo $str;
?>

输出

Hello

例子2

让我们通过另一个示例来理解按值调用PHP的概念。

<?php
function increment($i)
{
    $i++;
}
$i = 10;
increment($i);
echo $i;
?>

输出

10

来源:

https://www.srcmini02.com/29152.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_38059.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?