gpt4 book ai didi

PHP 评估 $a ="$a"?

转载 作者:可可西里 更新时间:2023-11-01 12:50:11 28 4
gpt4 key购买 nike

我正在查看一些工作代码,并遇到了这一行:

eval("\$element = \"$element\";");

我真的很困惑为什么任何 PHP 开发人员都会写这一行。除了给自己设置一个变量之外,这还有什么用?

幸运的是,此行所在的函数从未被调用。

最佳答案

<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
echo $str. "\n";
eval("\$str = \"$str\";");
echo $str. "\n";
?>

上面的例子会输出:

This is a $string with my $name in it.
This is a cup with my coffee in it.

http://php.net/manual/en/function.eval.php

我只是 ctl+c ctrl+v :-)

关于PHP 评估 $a ="$a"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5340442/

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