Francesco
Francesco

Reputation: 555

PHP: How to retrieve the parent array dimension having child

I want to create a function where i pass as parameter an array "position", something like this:

function f($pos){};
f($people[all][person][name]);

Then i want to retrieve the parent dimension of the array, so I want to have $people[all]. This way I could do a foreach cycle on all person.

My idea is to do a function where I pass the position and the function sort the "parent" dimension by the position given.

Common case:

$people[men][person][name]=>value
f($people[men][person][name])

will sort all men by their name.

How could I do that?

Upvotes: 0

Views: 63

Answers (1)

Exception
Exception

Reputation: 787

How about this

function f($pos){
foreach ($people[all][person] as $name){
echo $name;
}

}
f($people);

this will you name

Upvotes: 1

Related Questions