This is a cool problem. I've never done this before but you need a recursive function (a function that can call itself). This way, it doesn't matter how many levels deep the array goes, the function keeps calling itself every time the array goes another layer deep.
I just wrote this code and tested it and it works. The basic idea is that you are taking your array ($x) and you are building a new array ($result) that keeps track of any key and who its parent is. So after you run the code, then you can say, "Ok, I want to know who the parent is of key 17." and you would find out by saying:
$par = $result[17];
This is the code that builds the new array from your original array.
<?
$x=array();
$result = array();
$x[1][1] = "junk descriptive text";
$x[1][2] = "junk descriptive text";
$x[1][3] = "junk descriptive text";
$x[1][4] = "junk descriptive text";
$x[1][5] = "junk descriptive text";
$x[1][6] = "junk descriptive text";
$x[2][7] = "junk descriptive text";
$x[2][8] = "junk descriptive text";
$x[2][9] = "junk descriptive text";
$x[2][10] = "junk descriptive text";
$x[2][11] = "junk descriptive text";
$x[2][12] = "junk descriptive text";
$x[3][13] = "junk descriptive text";
$x[3][14] = "junk descriptive text";
$x[3][15] = "junk descriptive text";
$x[3][16] = "junk descriptive text";
$x[3][17] = "junk descriptive text";
$x[3][18] = "junk descriptive text";
$x[4][0][19] = "junk descriptive text";
$x[4][0][20] = "junk descriptive text";
$x[4][0][21] = "junk descriptive text";
$x[4][0][22] = "junk descriptive text";
$x[4][0][23] = "junk descriptive text";
$x[4][0][24] = "junk descriptive text";
foreach ($x as $parent => $value) {
if (is_array($value)) explode_v($parent,$value);
}
function explode_v($parent,$value) {
global $result;
foreach ($value as $key => $v1) {
if (is_array($v1)) explode_v($parent,$v1);
else $result[$key] = $parent;
}
}
print_r($result);
?>