Ser*_*hov 3 php smarty smarty2
我需要做出决定:
{math equation="x/y" x=$x y=$y} // $x = '2', $y = '3'
Run Code Online (Sandbox Code Playgroud)
如何在Smarty中完全将字符串转换为数字,因为我无法访问CMS的专有代码?感谢名单!
UPD:Smarty版本:2.6.18
如果已将其分配给变量,例如$ var,则可以设置变量的类型,如下所示:
{$converted = settype ($var, 'integer')}
Run Code Online (Sandbox Code Playgroud)
您不必使用$ converted值,但如果您不指定它,则bool将显示在您的页面中.
或者你可以试试
{$variable|intval}
Run Code Online (Sandbox Code Playgroud)
你可以试试这个{$variable|intval}
并且((int)$variable)
例如:
$x_new = (int) $x;
$y_new = (int) $y;
Run Code Online (Sandbox Code Playgroud)
在你的情况下:
{math equation="x/y" x=(int)$x y=(int)$y}
Run Code Online (Sandbox Code Playgroud)