Referencing multiple keys in an array
Posted: Tue Feb 02, 2010 3:28 am
I can't shake the feeling that there is something very basic I'm missing, but I've been trying various search phrasings and reading about arrays on different sites for several hours now and either haven't found the answer, or haven't understood well enough to recognize it.
I want to assign $p_type based on whether or not $tag matches any of keys 1 through 5 (that is, the second through sixth keys out of a longer list) in the associative array $queen_index. Is there a way to do this using something in place of the asterisked phrase below, or something of similar simplicity? Or is there really no way other than with a longer code structure such as a while or foreach?
I have ideas for various workarounds and have received suggestions for others, but all of them seem 'inelegant' -- adding further lines of code while requiring $p_type, $tag, and/or $queen_index to be reworked, along with substantial other sections dependent on them (I can provide further code for context if necessary, but for the moment explaining how these three items relate to the rest of the code would probably just muddy the waters needlessly). If that is necessary, then so be it, but if it can be avoided I'd like to.
The heart of my question therefore is, am I overlooking a basic way to state several specific keys from an array at once? It seems odd that there should be none.
I want to assign $p_type based on whether or not $tag matches any of keys 1 through 5 (that is, the second through sixth keys out of a longer list) in the associative array $queen_index. Is there a way to do this using something in place of the asterisked phrase below, or something of similar simplicity? Or is there really no way other than with a longer code structure such as a while or foreach?
Code: Select all
if ($tag == $queen_index [/*1 through 5*/]) { $p_type = "section"; }
else { $p_type = "subpage"; }The heart of my question therefore is, am I overlooking a basic way to state several specific keys from an array at once? It seems odd that there should be none.