gpt4 book ai didi

php - $this->{$key} 在 PHP 中是什么意思?

转载 作者:可可西里 更新时间:2023-10-31 22:09:36 24 4
gpt4 key购买 nike

以下代码有什么区别?

$this->idKey
$this->$idKey
$this->{$idKey}

最佳答案

读取 $this 对象的 idkey 属性:

$this->idKey;

读取$this对象的变量属性名称(在本例中为example)所以$this->example:

$idKey = 'example';
$this->$idKey;

同上($this->example),但歧义更少(类似于添加括号来控制操作数顺序,在某些情况下很有用):

$idKey = 'example';
$this->{$idKey};

这可能会增加清晰度或控制顺序的情况:

$this->{$idKey['key']};
$this->{$idKey}['key'];

关于php - $this->{$key} 在 PHP 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41254843/

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