cmccarroll
asked on
PHP multidimensional arrays
I need a recursive function to return the keys and values of a multidimensional array.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What are you trying to do with the results? Did you want to build a table?
ASKER
Yes, possibly muultiple tables if appropriate. I haven't thought that part through
What is the `reports` array? If possible you may need to restructure the way the array is built.
array('John' => array( 'position' => 'CEO', 'salary' => 240000, 'reports' => 'Mary')
'Mary' => array( 'position' => 'CIO', 'salary' => 120000, 'reports' => 'James')
)
Or I need a more descriptive explanation on what you are trying to accomplish.
Anybody else have any ideas?
array('John' => array( 'position' => 'CEO', 'salary' => 240000, 'reports' => 'Mary')
'Mary' => array( 'position' => 'CIO', 'salary' => 120000, 'reports' => 'James')
)
Or I need a more descriptive explanation on what you are trying to accomplish.
Anybody else have any ideas?
ASKER
The reports array is who the user "mary" reports to john. The user "james" reports to mary, etc. I agree the array iseems to be a little redundant, which I think is by design. I am unable to change the existing array. What I am tyring to accomplish is a table like this I believe;
user position salary reports
john ceo 240000
mary cio 120000 john
james Sales Rep 50000 mary
jason CS Rep 24000 mary
jules CS Rep 24000 mary
charlie CTO 120000 john
david Sys Admin 75000 charlie
chirs Tech Support 75000 david
sharron Developer 100000 charlie
user position salary reports
john ceo 240000
mary cio 120000 john
james Sales Rep 50000 mary
jason CS Rep 24000 mary
jules CS Rep 24000 mary
charlie CTO 120000 john
david Sys Admin 75000 charlie
chirs Tech Support 75000 david
sharron Developer 100000 charlie
okay stand by....
I'm sorry but this one is hurting my brain!
my plan was to restructure the array to allow proper parsing...
i cant get it to work properly and I've got to move on.
there is a plethora of php experts on this site somebody should be able to come up with a solution, just give it some time.
my plan was to restructure the array to allow proper parsing...
i cant get it to work properly and I've got to move on.
there is a plethora of php experts on this site somebody should be able to come up with a solution, just give it some time.
ASKER
Yea, it hurts my brain as well. Thanks anyway.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Very Nice hielo!
ASKER
Thanks a bunch. Y'all rock!
ASKER
$array = array( 'john' => array( 'position' => 'CEO', 'salary' => 240000,
'reports'=>array( 'mary' => array( 'position' => 'CIO', 'salary' => 120000,
'reports'=>array( 'james'=>array('position' => 'Sales Rep', 'salary' => 50000,
'reports'=>array() ),'jason'=>array( 'position' => 'CS Rep', 'salary' => 24000,
'reports'=>array() ),'jules'=>array( 'position' => 'CS Rep', 'salary' => 24000,
'reports'=>array() ) ) ), 'charlie'=>array( 'position' => 'CTO', 'salary' => 120000,
'reports'=>array( 'david'=>array( 'position' => 'SysAdmin', 'salary' => 75000,
'reports'=>array( 'chris' => array( 'position' => 'Tech Support', 'salary' => 24000,
'reports'=>array() ) ) ),'sharon'=>array( 'position' => 'Developer', 'salary' => 100000,
'reports'=>array() ) ) ) ) ) );