|
Posted by Darko on 05/24/07 21:48
On May 24, 11:20 pm, rbutle...@gmail.com wrote:
> Hi, I've racked my brain for the last few hours trying to figure
> this one out. I have an array of language strings such as :
>
> $lang = array();
> $lang['en']['prompt']['hello'] = 'hello';
> $lang['en']['prompt']['bye'] = 'goodbye';
> $lang['en']['number']['first'] = '1st';
>
> This is being used by an ajax routine, so I don't know which string
> will be requested at runtime. So, I've got $lang and a request
> ('en_prompt_hello'), and tried a few things such as:
>
> $request = explode ($request);
> $found_string = array_intersect_assoc ($lang, $request);
>
> to no avail. Short of having to do a complicated recursion searching
> at every available depth, is there an easy way to do this?
>
> Thanks...
OK, if you split your $request variable so it becomes an array of
consecutive keys that lead deep into the array $lang, then you can try
something like this:
$elem =& $lang;
foreach ( $request as &$key )
$elem =& $elem[$key];
// your $elem now is the value (haven't tried it though, but it should
be ok)
Navigation:
[Reply to this message]
|