Array "tree" creation from db table
        Posted  
        
            by 
                Tural Teyyuboglu
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Tural Teyyuboglu
        
        
        
        Published on 2011-11-22T01:30:16Z
        Indexed on 
            2011/11/22
            1:51 UTC
        
        
        Read the original article
        Hit count: 223
        
Trying to create array tree for db driven navigation. Getting following errur:
array_key_exists() expects exactly 2 parameters, 1 given on line if (!array_key_exists($tree[$parent]['children'][$id]))
Function looks like that
$tree = array();
$sql = "SELECT id, parent, name FROM menu WHERE parent ... etc.... ";
$results = mysql_query($sql) or die(mysql_error());
while(list($id, $parent, $name) = mysql_fetch_assoc($results)) {
    $tree[$id] = array('name' => $name, 'children' => array(), 'parent' => $parent);
    if (!array_key_exists($tree[$parent]['children'][$id])) {
        $tree[$parent]['children'][$id] = $id;
    }
}
Db structure

How can I fix that?
Whats wrong in this function?
© Stack Overflow or respective owner