Array woes
Posted: Mon Sep 10, 2007 2:14 pm
So, here is my issue.
Say I have the following array:
What I want to do, is track where I am in the array at all times. The issue is that I'm using a recursive function to loop through it, so everytime I find an array within my array, it calls itself back to loop through the array.
It loops fine and all that. that's not the problem. the problem is i want to keep track where in the filesystem array I am, so that I can map my input checkboxes to have the path as the name and the filename as the value.
ie, i'd like to have my checkboxes look like:
and so on. i'm trying to do this within the above function, but i can't seem to keep track where I am in the array! any help would be much appreciated...
Say I have the following array:
Code: Select all
array('home' => array(0 => 'jon.html',
'site' => array(0 => 'jon.html'),
),
'next' => array('site' => array(0 => 'jon.html',
'site' => array(0 => 'jon.html'),
),
),
);Code: Select all
function show_file_structure($array, $key_name = '', $is_parent = 1) {
global $array_map, $global_key;
if(!empty($key_name)) {
show_dir_tree_display($key_name);
}
if(is_array($array)) {
sort_array($array);
foreach($array as $key => $value) {
if(is_array($value)) {
sort_array($value);
show_dir_tree_display($key);
foreach($value as $sub_key => $sub_value) {
if(!is_array($sub_value) && !empty($sub_value)) {
echo "\n\n<input style=\"margin-right: 10px;\" type=\"checkbox\" name=\"$sub_value\" /> $sub_value<br>\n\n";
} elseif(is_array($sub_value)) {
show_file_structure($sub_value, $sub_key, 0);
}
}
echo "</div>";
} else {
echo "\n\n<input type=\"checkbox\" name=\"$value\" /> $value<br>\n\n";
}
}
}
echo "</div>";
}It loops fine and all that. that's not the problem. the problem is i want to keep track where in the filesystem array I am, so that I can map my input checkboxes to have the path as the name and the filename as the value.
ie, i'd like to have my checkboxes look like:
Code: Select all
<input type="checkbox" name="/htdocs/next/site/" value="jon.html" />
<input type="checkbox" name="/htdocs/" value="jon.html" />
<input type="checkbox" name="/htdocs/site/" value="jon.html" />