phpfor-loopsmartysmarty3

Smarty:- Create an associative array using for loop and check wheather value exists in array


i am new to smarty and a dont know how to Create an associative array using for loop and check wheather value exists.

But i created the array in php and checked value exists.

Can anyone help me to code the same in smarty tpl file

<?php
$newArray=array();
for($i=0; $i<=10; $i++){
$newArray[]=$i;
}
if (in_array("5", $newArray)) 
{ 
echo "found"; 
} 
else
{ 
echo "not found"; 
} 

Solution

  • Try this.

    {for $foo=0 to 10}
    {$newArray[] = $foo}
    {/for}
    
    {if (in_array("5", $newArray))} 
    found
    {else}
    not found
    {/if}