这个问题我纠结了好久,希望有大神指点一下。这是代码:
<?php
$Trucking_CPA="25.00"; // set price
$Trucking_price="\$Trucking_CPA"; // I know, that slash is the problem - but I need it there for other purposes in the program.
echo $Trucking_CPA."<br />"; // prints $25.00 - that's fine and expected
echo $Trucking_price."<br />"; // prints $Trucking_CPA (with no slash for some reason...)
echo $$Trucking_price."<br />"; // With double $ - Gives error: Notice: Undefined variable: $Trucking_CPA - why?
$anothertry1 = ${$Trucking_price};
echo $anothertry1."<br />"; // With double $ in brackets - Gives error: Notice: Undefined variable: $Trucking_CPA - why?
$anothertry2 = ${stripslashes($Trucking_price)};
echo $anothertry2."<br />"; // With double $ in brackets and stripslashes - Gives error: Notice: Undefined variable: $Trucking_CPA - why?
?>
我需要在那里有那个斜线,所以它不会在其他地方转换,因为逻辑正在检查它,在这种情况下它不能等于变量的值。
任何人都知道如何通过调用 $Trucking_price 让 PHP 给我 25.00?
更新- 这个问题在下面得到了很好的回答,所以只是为了让未来的用户遇到这个问题:
<?php
$Trucking_CPA="25.00"; // set price
$Trucking_price="\$Trucking_CPA";
echo ${substr($Trucking_price,1)}; // returns 25.00 instead of $Trucking_CPA
?>