Forums / Setup & design / Initialize a hash and add items to it

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

Initialize a hash and add items to it

Author Message

Softriva .com

Saturday 02 December 2006 2:18:54 am

How can I initialize a hash and add item to it inside a loop (foreach)?

Claudia Kosny

Saturday 02 December 2006 3:02:40 am

Hi OOzy

{def $hash = hash('key1', 'value1')
     $keyArr = array('key2', 'key3', 'key4')
     $valueArr = array('value2', 'value3', 'value4')}
{foreach $keyArr as $cnt => $key}
 {set $hash = $hash|merge(hash($key, $valueArr[$cnt]))}
{/foreach}
{$hash|attribute('show')}

Does not look very efficient but it seems to be the only way.

Claudia