henka Posted August 2, 2006 Share Posted August 2, 2006 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? Quote Link to comment Share on other sites More sharing options...
effigy Posted August 2, 2006 Share Posted August 2, 2006 Why not foreach? I think that is as short as you're going to get without it. Although, you could try [url=http://us3.php.net/extract]extract[/url]. Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 2, 2006 Share Posted August 2, 2006 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) Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 2, 2006 Share Posted August 2, 2006 the way you have it there, you'll have to type the keys again anyway.. can you post the code so we know exactly how are you doing it?? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.