Multidimensional Array
Posted: Tue Dec 02, 2003 5:06 pm
OK, I'll admit arrays are by no way my strong point, and I usually try to avoid them, but it's time I address my fears and hit it head on.
An application I am working on has me configuring a fairly complex Array (which I might have done wrong in itself)
Here is the array of employees
Now I can do a print_r ($plantA); and see that the array has been constructed. I have even figured out how to get at some of the array using the foreach statement
But I'm afraid I am stuck at that point, I am having problems how to visualize what I need to get done. Basically there are two things I'm looking to do
1) Print out the directory of employees in basic columns of Name Role Phone Email. I got a lot of this licked but I can't figure out how to logically pull all the information from each array.. Mainly how to permeate through the Roles array on each person.
2) Also, on each individual "Line's" page, display that Line's Manager. For example on the page for Line3 it would display the manager as Bob Allxon. I'm not sure how to perform that type of search function on an array to get that result.
Any pointers would be greatly appreciated even it was to redesign the array. Database is not an option for this site besides, like I said I would really appreciate understanding arrays.
An application I am working on has me configuring a fairly complex Array (which I might have done wrong in itself)
Here is the array of employees
Code: Select all
<?php
$plantA = array(
"Mike Mann" => array(
"Roles" =>array ("Owner" => "Owner", "CEO" => "CEO"),
"Phone" => "(555) 555-5555",
"Email" => "mike@plantA.com"),
"Sam Newal" => array(
"Roles" =>array ("Owner" => "Owner", "CTO" => "CTO"),
"Phone" => "(555) 555-5554",
"Email" => "sam@plantA.com"),
"Bob Allxon" => array(
"Roles" => array ("Safety Manager" => "Safety Manager",
"Line Manager" => array ("Line1", "Line2", "Line3")),
"Phone" => "(555) 555-5556",
"Email" => "bob@plantA.com"),
"Steve Dunn" => array(
"Roles" => array ("Line Manager" => array ("Line4", "Line5", "Line6")),
"Phone" => "",
"Email" => "steve@plantA.com")
);
?>Code: Select all
<?php
foreach ($plantA as $key => $plantA)
{
print ("$key - ");
foreach ($plantA as $key2 => $info)
{
print ("$info <br> \n");
}
}
?>1) Print out the directory of employees in basic columns of Name Role Phone Email. I got a lot of this licked but I can't figure out how to logically pull all the information from each array.. Mainly how to permeate through the Roles array on each person.
2) Also, on each individual "Line's" page, display that Line's Manager. For example on the page for Line3 it would display the manager as Bob Allxon. I'm not sure how to perform that type of search function on an array to get that result.
Any pointers would be greatly appreciated even it was to redesign the array. Database is not an option for this site besides, like I said I would really appreciate understanding arrays.