==== PROBLEM ====Code works on laptop with PHP 5Not on server with PHP 4My guess is there is a ByRef problem with the added items in _question_shake_tree()= line => $root->children[$item->id] = $item;==== CODE ====function _question_tree_builder( $list, $root){ $root->children=array();print_r( array( 'initial root'=> $root)); /* each item has a parent value */ /* * try to add an item into the current tree * at least 1 item should succeed */ $succes=true; while($succes){ $succes= false; foreach( $list as $id => $item){print_r(array( "root before shake"=> $root)); if(_question_shake_tree( $root, $item)){print_r(array( "root after shake"=> $root)); $succes= true; break; }else{print_r(array('unsuccesfull shake'=>array( 'root'=>$root,'item'=>$item))); } } if( $succes){ unset($list[$id]); } }}function _question_shake_tree( &$root, &$item){ if(($root->id== $item->parent)){ // add all items to the children $root->children[$item->id] = $item;print_r( array( 'Matching parent--child'=> array( 'root'=> $root, 'item'=>$item))); return TRUE; } else { if(isset($root->children)){ foreach($root->children as $subtree){ if( _question_shake_tree($subtree, $item)){ return TRUE; } } } else {//print_r( array( "FALSE with", 'root'=>$root, 'item'=>$item)); return FALSE; } } return FALSE;}===== On server ====// See http://questionary.build2be.com/?q=node/1/questions