You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Keith Vance <kv...@n-link.net> on 2001/06/11 22:45:21 UTC

foreach ($hash as $key=>$val) ?

Is there a Velocity way to do something like this on a Hashtable or
HashMap?

This is what I would do in PHP:

foreach ($hash as $key=>#val) {
	print ("key: " . $key);
	print ("val: " . $val);
}

Just checking before I go overboard trying to make it happen. I thought
someone had mentioned this subject before, but I can't seem to find the
message.

-- 
K E I T H  V A N C E
Software Engineer
n-Link Corporation


Re: foreach ($hash as $key=>$val) ?

Posted by Jon Stevens <jo...@latchkey.com>.
on 6/11/01 1:45 PM, "Keith Vance" <kv...@n-link.net> wrote:

> Is there a Velocity way to do something like this on a Hashtable or
> HashMap?
> 
> This is what I would do in PHP:
> 
> foreach ($hash as $key=>#val) {
> print ("key: " . $key);
> print ("val: " . $val);
> }
> 
> Just checking before I go overboard trying to make it happen. I thought
> someone had mentioned this subject before, but I can't seem to find the
> message.

Try this...

#foreach ($key in $hash.keys())
Key: $key
Value: $hash.get($key)
#end

The javadoc for the Hashtable object is here:

<http://java.sun.com/products/jdk/1.2/docs/api/java/util/Hashtable.html>

Notice that one of the differences between PHP and Velocity in this example
is that Velocity will encourage you to not embed HTML code within your code
because it doesn't require you to put everything into a "print" statement.

:-)

-jon

-- 
"Open source is not available to commercial companies."
            -Steve Ballmer, CEO Microsoft
<http://www.suntimes.com/output/tech/cst-fin-micro01.html>


Re: foreach ($hash as $key=>$val) ?

Posted by bob mcwhirter <bo...@werken.com>.
#foreach ( $key in $map.keySet() )
	key: $key
	value: $map.get( $key )
#end

My syntax might be slightly wonky, but that's the
general idea.

	-bob

On Mon, 11 Jun 2001, Keith Vance wrote:

> Is there a Velocity way to do something like this on a Hashtable or
> HashMap?
> 
> This is what I would do in PHP:
> 
> foreach ($hash as $key=>#val) {
> 	print ("key: " . $key);
> 	print ("val: " . $val);
> }
> 
> Just checking before I go overboard trying to make it happen. I thought
> someone had mentioned this subject before, but I can't seem to find the
> message.
> 
> -- 
> K E I T H  V A N C E
> Software Engineer
> n-Link Corporation
>