Php 在变量上使用函数有没有简写法?

Php 在变量上使用函数有没有简写法?,php,Php,例如: $json['errorinfo']['customers']['some_swedish_name'] = utf8_encode($json['errorinfo']['customers']['some_swedish_name']); 有了足够的嵌套,这可能会变得很长且不可读。 有没有办法避免同一个变量输入两次 差不多 $json['errorinfo']['customers']['some_swedish_name'] = utf8_encode($this); 我知道你

例如:

$json['errorinfo']['customers']['some_swedish_name'] = utf8_encode($json['errorinfo']['customers']['some_swedish_name']);
有了足够的嵌套,这可能会变得很长且不可读。 有没有办法避免同一个变量输入两次

差不多

$json['errorinfo']['customers']['some_swedish_name'] = utf8_encode($this);
我知道你能做到

$a = $json['errorinfo']['customers']['some_swedish_name'];
$a = utf8_encode($a);

但这也相对不方便。

您是否尝试过通过引用传递(使用
&
符号),例如:

$ref=&$json['errorinfo']['customers']['some_-swedish_-name'];
$ref=utf8\u编码($ref);
&
(符号)确保自动更新
$json
数组,否则它可能会如下所示:

$x=$json['errorinfo']['customers']['some_-swedish_-name'];
$x=utf8\U编码($x);
$json['errorinfo']['customers']['some_swedish_name']=$x;

一次只要求一种语言。对于多种语言,这(至少)是两个不同的问题,而你应该一次问一个问题。值得一提的是,我不知道JS和PHP中有任何语法或语言特性可以这样工作。创建一个变量或重新构造代码。如果这是您要重复的内容,并且需要某种速记方式来处理,则可以编写一个函数来处理它
$a=$json['errorinfo']['customers']['some_-swedish_-name']$a=utf8_编码($a)在我看来很好。正如@tshimkus所建议的,如果你不想重复你自己,你可以把它放在一个函数中。我是否遗漏了什么,或者你就不能这样做,
$a=utf8\u encode($json['errorinfo']['customers']['some\u-swedish\u-name'])