日期:2014-05-17 浏览次数:20495 次
<?php
function get_employees_by_hierarchy( $_employee_id = 0,$_depth = 0,$_org_array = array() ) {
if ( $this->org_depth < $_depth ) {
$this->org_depth = $_depth;
}
$_depth++;
$_query = "SELECT * FROM employees WHERE ";
if ( !$_employee_id ) {
$_query .= "employee_manager_id IS NULL OR employee_manager_id = 0";
}
else {
$_query .= "employee_manager_id = " . $this->dbh->quoteSmart( $_employee_id );
}
$_result = $this->query( $_query );
while ( $_row = $_result->fetchRow() ) {
$_row['depth'] = $_depth;
array_push( $_org_array, $_row );
$_org_array = $this->get_employees_by_hierarchy(
$_row['employee_manager_id'],
$_depth,
$_org_array
);
}
return $_org_array;
}
?>
这段代码还可以做怎么样的优化啊? 3-5行为什么很重要? 17行为什么很重要? 小弟刚开始学php,求大神的指教哦~