就我个人而言,我发现 in 关键字令人困惑。 PHP 本身并不知道。 Javascript 是唯一与模板开发人员相关的其他编程语言,它将 in 关键字视为 array_key_exists() 而不是 in_array()。不确定我是否想要给定的模板引擎做一些不同的事情......
yes and no. Smarty does not have its own syntax for this, but you can do it like this:
{if in_array("foo", ["bar", "foo"])}
Personally I find the in keyword confusing. PHP itself doesn't know it. Javascript, the only other programming language relevant to a template developer, treats the in keyword as array_key_exists() rather than in_array(). Not sure if I wanted a given template engine to do something different…
发布评论
评论(1)
是和否。 Smarty 没有自己的语法,但您可以这样做:
就我个人而言,我发现 in 关键字令人困惑。 PHP 本身并不知道。 Javascript 是唯一与模板开发人员相关的其他编程语言,它将 in 关键字视为
array_key_exists()
而不是in_array()
。不确定我是否想要给定的模板引擎做一些不同的事情......yes and no. Smarty does not have its own syntax for this, but you can do it like this:
Personally I find the in keyword confusing. PHP itself doesn't know it. Javascript, the only other programming language relevant to a template developer, treats the in keyword as
array_key_exists()
rather thanin_array()
. Not sure if I wanted a given template engine to do something different…