Forum Moderators: coopster
$sm_array = array();
while ($fetch = mysql_fetch_object($results)) {
if (count(explode("-", $fetch->parent)) >=2){
$exp = explode("-", $fetch->parent);
$test = "";
foreach ($exp as $key=>$val){
$test .= "[$val]";
$sm_array{$test}[$fetch->id]= "$fetch->title";
}
}
if fetch->parent is something like "test-test-test"
then the key in sm_array ends up being
[[test][test][test]] => Array
()
Is it possible to do what I am trying to do, or does anyone know a better way? (this structure at most will be 5 deep but I don't want to limit it)
$exp = explode("-",$test_str);
foreach ( $exp as $val ) {
if (!isset($sm_array) ) {
$sm_array[$val] = array();
$last_array = &$sm_array[$val];
} else {
$last_array[$val] = array();
$last_array = &$last_array[$val];
}
}
Using the above $test_str, the code makes the multidimensional array $sm_array[test1][test2][test3]. Is that what you were looking for? Hopefully I understood your question completely.