gpt4 book ai didi

php - 为什么我会收到 "Only variables should be passed by reference"错误?

转载 作者:可可西里 更新时间:2023-10-31 22:54:19 26 4
gpt4 key购买 nike

检查这段代码:

$last = end($p = explode('/', $someString));  

收到此通知:

Only variables should be passed by reference

我真的很困惑,因为 $p 是一个变量。

最佳答案

end() 需要一个变量,而不是一个引用。在你的例子中 $p = explode('/', $someString) 不是一个变量,它是一个赋值。作为documentation说:

This array is passed by reference because it is modified by the function. This means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference.

你应该这样做:

$p = explode('/', $someString);
$last = end($p);

关于php - 为什么我会收到 "Only variables should be passed by reference"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20776017/

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