tags:

views:

33

answers:

3

How do I create an array in smarty from a given string like 22||33||50 and look if the given number is like the numbers above in smarty ?

I have a string say

{$test->strings} // contains 33||12||80 

I want to look if one of the numbers in {$test->strings} is equal to {$test->myday}

how can I do that?

+1  A: 

Don't know about Smarty but this is how you'd do it in pure PHP:

if(in_array($test->myday, explode('||', $test->strings))) {
    // strings contains myday
}

Hope that helps.

Tatu Ulmanen
+1  A: 

You really shouldn't be getting your view (smarty template) to perform any data manipulation, in my opinion. I would convert your string to an array before you send it to the template.

$str = "33||12||80";
$array = explode("||", $str);  // [33, 12, 80]

if (in_array($test->myday, $array)) {
    // it's in there
}
nickf
I know about this but i have to do it, i also know it could be bugy how every thnks
streetparade
A: 

You shouldn't do a such things in template. You should do necessary operations in you application logics (PHP) and pass the results to the template.

By the way: Smarty (and all Smarty-like engines) is a piece of... rubbish.

Crozin