Jump to content

How to split hash key and value without using "foreach"


henka

Recommended Posts

I just can't see the obvious here, so forgive the question if it seems silly.

Given the following:

$array['keyval'] = "some data";

Is there a shorter way of coding this expression:

$val = $array['keyval'] ? $array['keyval'] : 'keyval';

The above may seem quite short already, but my code uses some rather long 'keyval' strings, eg:

$val = $array['this is a rather long string...'] ? $array['this is a rather long string...'] : 'this is a rather long string...';

In other words, without using "foreach ($array as $key => $val)", I want to get at the $key string of a hash.

Any ideas?
Don't you want to use foreach for a specific reason? If you want to access all keys you'll have to do some looping, whether foreach or after an extract or key/next combinations or whatever key extraction you want to use.

Ronald  8)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.