Page 1 of 1

Associated array problem

Posted: Wed Feb 24, 2010 6:19 am
by NinjaBot
I've got a function that lists pages from several directories. However, I am having trouble ordering them (at present, they're ordered as groups from their respective parents, rather than collectively as I want):

Code: Select all

<div class="members">
<ul>
<?php
$members = array();
function snippet_fullmenu($parent){
    global $members;
    $out = '';
    $childs = $parent->children(null, array(), true);
    $exclude = array("");
    if (count($childs) > 0){
    foreach ($childs as $child)
        /* Don't display specific pages */
        if(!in_array($child->breadcrumb(),$exclude)){
            $depth = substr_count($child->link(), '/');
            if($depth == 7){    
                $split_name = explode(" ", $child->title());
                $surname = isset($split_name[2]) ? $split_name[2] : $split_name[1]; 
                $entry = '<li>'.$child->link($child->breadcrumb.', '.$child->content('practice')).', '.$surname.'</li>'."\r";
                $out .= $entry;
                $members[$surname] = $entry;
            }
            $out .= snippet_fullmenu($child);
        }
    }
    return $out;
}
?>
<?php
 
echo snippet_fullmenu($this->find('/members/'));
 
    //ksort($members);
    //echo $members['Louw'];
    //foreach ($members as $s => $value){
    //print $count++;
        //print($value . "<br>");
    //}
 
?>
</ul>
</div>
If you look at the commented array that I try to print at the bottom, you can see I have tried to return an ordered list by adding my results to an associated members array as an alternative, however it appears to duplicate the results.

Can anyone help!?

Re: Associated array problem

Posted: Wed Feb 24, 2010 6:56 am
by NinjaBot
I got it ... my members array was set as global within the function, but not outside the function. Setting the members array to global outside of the function allowed the array to be built correctly.