I'm using this recursive function to get the grand parent of an option. As far as the needle exists in the array keys, it mean that needle has a parent. When not found, then the needle do not have any parent, so it must return the needle itself.
get_parent_need(165,$hay);
function get_parent_need($needle,$hay){
if(in_array($needle,array_keys($hay))){
get_parent_need($hay[$needle],array_keys($hay));
}else{
return $needle;
}
}