Smarty change elements in array – Education Career Blog

I have an array in my template files ($data) witch looks like this

$data.1.name
$data.1.date
$data.1.place
$data.2.name
$data.2.date
$data.2.place
$data.3.name
$data.3.date
$data.3.place

now I would like to check the entire array and remove an item where the date is older then today.
The date check i figured out but i’m stuck at removing the item.

So let’s say item 2 is older, the result should look like

$data.1.name
$data.1.date
$data.1.place
$data.3.name
$data.3.date
$data.3.place

Anyone an idea how i do this? If it is at all possible?

,

{foreach from=$data item=val}
  {if $val.date >= $smarty.now}
    {$val.name}
    {$val.date}
    {$val.place}
  {/if}
{/foreach}

Leave a Comment