我想知道如何使用与 eval 函数完全相反的函数。
这是我的代码:
$test = 1;
$t = '$test';
echo opposite_eval($t);
我必须1
从上面的代码输出,我如何使用方法、函数或类?
感谢您的尊重帮助朋友!
我想你想要一个变量变量
在您的情况下,它将是:
$test = 1;
$t = 'test';
echo $$t;
// output: 1
插件:
你也可以做这样的事情:
$test['x'] = 1;
$t = 'test';
echo $$t['x'];
而这将不工作:
$test['x'] = 1;
$t = "test['x']";
echo $$t;
// Produces: NOTICE Undefined variable: test['x'] on line number 6
也不会:
$test = new stdClass();
$test->x = 1;
$t = "test->x";
echo $$t;
但这会起作用:
$test = new stdClass();
$test->x = 1;
$t = "{$test->x}";
echo $t;
这也将起作用:
$test =[];
$test['x'] = 1;
$t = "{$test['x']}";
echo $t;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句