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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 01:26:53
Script start
Timing: Jan 31 2025 01:26:53
Module start 'layout'
Timing: Jan 31 2025 01:26:53
Module start 'content'
Timing: Jan 31 2025 01:26:53
Module end 'content'
Timing: Jan 31 2025 01:26:53
Script end

Main resources:

Total runtime0.0192 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0045 588.2500151.2266
Module start 'layout' 0.00450.0032 739.4766220.7188
Module start 'content' 0.00770.0102 960.1953997.7266
Module end 'content' 0.01790.0013 1,957.921929.9922
Script end 0.0192  1,987.9141 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002312.0258140.0002
Check MTime0.00094.6767140.0001
Mysql Total
Database connection0.00073.802510.0007
Mysqli_queries0.002010.479730.0007
Looping result0.00000.042210.0000
Template Total0.00105.210.0010
Template load0.00083.932810.0008
Template processing0.00021.260410.0002
Override
Cache load0.00052.776710.0005
General
dbfile0.00031.438080.0000
String conversion0.00000.037340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs