Need help in analysing a PHP Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
reyara8
Forum Newbie
Posts: 1
Joined: Wed Oct 15, 2008 7:00 pm

Need help in analysing a PHP Code

Post by reyara8 »

1 function get_employees_by_hierarchy( $_employee_id = 0,$_depth = 0,$_org_array = array() ) {
2 if ( $this->org_depth < $_depth ) {
3 $this->org_depth = $_depth;
4 }
5 $_depth++;
6 $_query = "SELECT * FROM employees WHERE ";
7 if ( !$_employee_id ) {
8 $_query .= "employee_manager_id IS NULL OR employee_manager_id = 0";
9 }
10 else {
11 $_query .= "employee_manager_id = " . $this->dbh->quoteSmart( $_employee_id );
12 }
13 $_result = $this->query( $_query );
14
15 while ( $_row = $_result->fetchRow() ) {
16 $_row['depth'] = $_depth;
17 array_push( $_org_array, $_row );
18 $_org_array = $this->get_employees_by_hierarchy(
19 $_row['employee_manager_id'],
20 $_depth,
21 $_org_array
22 );
23 }
24 return $_org_array;
25 }

Follow Up Questions:
1.Using the function declaration above, explain whether or not the function has any errors in it, what its purpose is and any optimizations you think can be made. Be sure to include descriptions of the passed arguments and function output, if any. Be sure to state your assumptions

2.Speculate why lines 2 – 4 are necessary.

3.Speculate why line 16 is necessary
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Need help in analysing a PHP Code

Post by requinix »

Sounds like a homework question.

Tsk tsk.
Post Reply