English 中文(简体)
• 如何在聪明创造价值
原标题:How to cast a value as integer in Smarty
  • 时间:2010-06-10 21:35:13
  •  标签:
  • php
  • smarty

在Sarty阵列中的参考指数方面遇到一些麻烦。 我认为,这是因为我使用指数时的变量是显而易见的。 我如何在模板中把这种扼杀当作一种愤怒?

感谢。

最佳回答

documentation 有许多使用实例,特别是在获取阵列要素方面。

{$foo}        <-- displaying a simple variable (non array/object)
{$foo[4]}     <-- display the 5th element of a zero-indexed array
{$foo.bar}    <-- display the "bar" key value of an array, similar to PHP $foo[ bar ]
{$foo.$bar}   <-- display variable key value of an array, similar to PHP $foo[$bar]
{$foo[bar]}   <-- syntax only valid in a section loop, see {section}
问题回答

如果我正确理解问题,{$vari intval}

I believe that it is because the variable I am using as the index is a string

我不同意这种看法:

$arr = array( a );
$i =  0 ;
echo $arr[$i]; // echos a

我认为问题在于其他地方。 如果你有进一步的问题,你应列入你的一些法典。

如果它已经分配到变量,即美元,那么你就可以确定这样的变量类型:

{$converted = settype ($var,  integer )}

你不必使用折中值,但如果你没有分配,则ool将在你的网页上展示。

既然不允许我发表评论(doh),那么就只能说,@webbiedave代码在实验室是正确的,但用粗略地说,它就是要做的。 i 仅仅花了太多时间试图说明为什么不从模板中阵列获取数据,而且发现,一阵有惯用钥匙和用于婚姻中关键参数,因此它会像预期的那样努力工作。 i 解决:

<!--{debug says}
    {$item}=> Array (2)      
      name=> "lalala"
      id => "123"
      ...

    {$arrays} => Array (7)
       123=> Array (3)
          other_part_i_care=> "bebebe"
          ...
-->
{$arrays[$item.id].other_part_i_care}  <!--this doesnt return anything-->

{assign var= item_id  value=$item.id}  <!--my guess here it gets interpreted as int -->
{$arrays[$item_id].other_part_i_care}  <!--this return expected outcome-->




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签