Forums / Developer / Remove an element from an array

Remove an element from an array

Author Message

Eirik Alfstad Johansen

Friday 13 August 2004 3:47:10 am

Hi guys,

What's the easier way to remove an element from an array (using the template language) when the item value (not the key) is know.

I've tried various loops, but can't seem to get it to work.

Thanks in advance !

Sincerely,

Eirik Johansen
http://www.netmaking.no/

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Paul Forsyth

Friday 13 August 2004 4:30:35 am

Would this work (quickly written):

$knownValue=""
$newArray=array();

{section var=Item loop=$oldArray}

  {section show=ne($Item, $knowValue)}
    $newArray|append($Item)}
  {/section}

{/section}

{set oldArray=$newArray}

It uses an extra array for this...

Eirik Alfstad Johansen

Tuesday 31 August 2004 11:49:01 am

Thanks a lot, Paul. BTW, here's the code I ended up with:

{let newArray=array()}
{section loop=$node.object.parent_nodes}
  {switch match=$:item}
  	{case match=128}
	{/case}
	{case}
		{let newArray=$newArray|append($:item)}
	{/case}
  {/switch}
{/section}
{/let}

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/