私はかなり長い間これについて困惑してきました。誰かがアイデアを持っていることを願っています。コードは次のとおりです。
<?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
?>