[eluser]seanloving[/eluser]
@sophistry - YAML might be the right way to prepare the $regions array
@helmutbjorg - I think you are right about the need for a recursive function
@BrianDHall - I think I'm doing something like you are suggesting - with strstr()
---------------
I ALMOST got this working... can somebody PLEASE help?
Once again, here's my desired output...
Code:
<div id="box">
<div id="left">
<div id="top"></div>
<div id="bottom"></div>
</div>
<div id="right"></div>
</div>
But here is the actual output of my code
Code:
<div id="box">
<div id="left">
<div id="top"></div>
<div id="bottom"></div>
<div id="right"></div>
</div>
</div>
And here is my code:
Code:
// pass this function an array of view partials (a.k.a. regions, a.k.a. strings)
// use this function to hierarchically structure (with div tags) the $regions
function structure( &$regions=array() )
{
foreach( $regions as $parent=>$content )
{
// opening wrapper for this region
echo "<div id=\"$parent\"><b>$parent</b> OPEN";
// remove this region now that it has been rendered
unset( $regions[$parent] );
// see if this region is a parent of any remaining regions
foreach($regions as $child=>$data)
{
if( ($parent & strstr($child,$parent)) )
{
// at least one child was found so recurse
$regions = $this->structure( $regions );
echo "<b>$parent</b> CLOSED</div>";
return $regions;
}
}
echo "<br><b>".$parent."</b> CLOSED</div>";
}
}
I call that function like this:
Code:
// This is a test array. Remove it.
$regions = array( 'box' => 'the main box',
'box_left' => 'the box on the left inside the main box',
'box_left_top' => 'the box on the top inside the left box',
'box_left_bottom' => 'the box on the bottom inside the left box',
'box_right' => 'the box on the left inside the main box'
);
$regions = $this->structure( $regions );
Anyone? Please!! Thanks!
--Sean Loving