0

I hope this is no stupid question, but I have no idea how to deal with this: There is a given associative array and I must get its values with one function. The function should look like:

function getValFromArray([$key1, $key2, $key3, ...]);

The given Array is flexible and looks like (example):

$arr = [
    'foo' => [
        'bar' => [
            'baz' => [
                'qux' => [
                    'quux' => 7
                ]
            ]
        ]
    ],
    'foo2' => [
        'bar2' => 1
    ]
];

Calling the function should now return:

echo getValFromArray(['foo', 'bar', 'baz', 'qux', 'quux']); // -> 7

And with other parameters:

echo getValFromArray(['foo2', 'bar2']); // -> 1

Is there a fast solution to get these values from the array, maybe with own PHP build in functions?

clausnz
  • 37
  • 1
  • 4
  • Didn't see question although I was looking before asking. Thank you for the hint! – clausnz Oct 23 '16 at 13:08
  • It isn't the most common duplicate, so it wasn't an easy one to find if you don't know what you need. (Also 2 question improvements: 1) If you didn't found a PHP function for your task try to write it yourself and show the attempt in your question 2) "Thanks" in a question is considered noise and you don't have to include it: http://meta.stackexchange.com/q/2950) – Rizier123 Oct 23 '16 at 13:34
  • Sorry, I did not know that either and edited the question. Thank you again! I hope I'm allowed to say that in the comments. – clausnz Oct 24 '16 at 21:47
  • Strictly speaking it is also considered as noise, but it isn't a real problem if you do it :) On Stack Overflow if you ask a question you don't have to write "Thanks", because we know that you are here looking for an answer. And if you want to say "thanks" to an answer you upvote/accept it. – Rizier123 Oct 24 '16 at 21:54
  • Ok, I'll pay attention in the future! – clausnz Oct 25 '16 at 10:31

0 Answers0