Share » Forums » Developer » Appending an array with a...

Appending an array with a concatenated string of variables

Appending an array with a concatenated string of variables

Tuesday 12 April 2011 8:44:29 am - 2 replies

Author Message

André R.

Tuesday 12 April 2011 1:33:42 pm

append does not change the array, it generates a new array. So you need to use se:

{set $names = $names|append(....)}

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Mark Yasuda

Wednesday 13 April 2011 1:27:27 am

That's great, thanks André!
The documentation seems a little confusing regarding this, I'll add a comment to it so hopefully others may benefit.

Thanks again,

Mark

edit: seems like documentation comments were locked down due to spamming.
oh well... maybe someone from eZ docs team will see this and expand on the array append page to reflect that the array does not modify the original input array. Perhaps another example as below:

Example 3

{set $foo = array( 1 , 2 , 3 )}
{set $bar = array( 'red' , 'blue' , 'green' )}
{set $result = $foo|append( $bar )}

Array $result contains: ( 1, 2, 3, 'red', 'blue', 'green' ).

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu