send array key function and get the result

Hi there

I want to send a key of multi deminition array to a function and get the value of that key, it should be an item or and sub array. Imagine I have this function:




public function returnArray($index){

        $arr = [

            'name' => 'ali',

            'children' => [

                '1' => 'reza',

                '2' => 'hasan',

                '3' => 'farhad',

                'info' => [

                    'a',

                    'b',

                    'c'

                ]

            ]

        ];

        return $arr[$index];

    }



and when I call it like this:




returnArray('[name][children][info]')



the result should be info from that array.

What should I do?

Thanks in advance.

I think something like that was introduced to Yii’s ArrayHelper recently…