gpt4 book ai didi

php - 变量前的&符号是什么意思?

转载 作者:可可西里 更新时间:2023-11-01 13:04:21 26 4
gpt4 key购买 nike

我正在“剖析”PunBB,其功能之一是检查 BBCode 标签的结构并尽可能修复简单的错误:

function preparse_tags($text, &$errors, $is_signature = false)

$error变量前的&是什么意思?

最佳答案

意思是pass the variable by reference ,而不是传递变量的值。这意味着当程序流返回到调用代码时,preparse_tags 函数中对该参数的任何更改都将保留。

function passByReference(&$test) {
$test = "Changed!";
}

function passByValue($test) {
$test = "a change here will not affect the original variable";
}

$test = 'Unchanged';
echo $test . PHP_EOL;

passByValue($test);
echo $test . PHP_EOL;

passByReference($test);
echo $test . PHP_EOL;

输出:

Unchanged

Unchanged

Changed!

关于php - 变量前的&符号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4175474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com