1
votes

I'm facing an issue while searching for a specific key value in a nested array. Below it the example of array I'm dealing with.

$this->strings = [
        'group_one => [
            'name_one' => "string g-one-one",
            'name_two => "string g-one-two",
            'name_three' => "string g-one-three",
        ],
        'group_two' => [
            'name_one' => "string g-one-one",
            'name_two => "string g-one-two",
            'name_three' => "string g-two-three",
        ],
        ...
    ],

I'm trying to get a search function running in order to have get_string( 'goup-one', 'name-two'); return "string g-one-two

I tried with a RecusrsiveArrayIterorator, foreach loops, but i cannot seem to output something, always returning NULL.

Could use a bit of a help here.

Thanks

1
Why is $this->strings['group_one']['name_two'] not working? - lokilein
Please share your attempts to resolve the problem - Nico Haase
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. - Community

1 Answers

-1
votes

You have a couple of spelling mistakes in your function call. You are getting null because of that. You are using - in one place and _ in another place. Also group is spelled as goup.

Issue in code : enter image description here

Below is a solution to your problem statement.

enter image description here