fairly new to PHP and these arrays are a bit over my head.

So, I have a task to parse roughly 200 lines of an array into drop down lists, allow users to update the info, then dump that updated info into mysql. I think I have the database manipulation down, but I’m not sure where to start with the arrays. Below is a sample of the array.
[php]
$dogs = array(
“Anthropology” => new DOGS(‘http://www.anthro.utah.edu’,‘M.A., M.S., Ph.D.’,‘Richard Paine’,‘[email protected]’,‘581-4021’,
new DEPT(“102 ST”,“Ursula Hanly”,“581-6251”)
),
“Architecture + Planning” => new DOGS(‘http://www.arch.utah.edu’,‘M.S., M.Arch, joint M.Arch.-M.B.A’,‘Peter Atherton’,‘[email protected]’,‘581-6347’,
new DEPT(“235 AAC”,“Kathy Thompson (3/09)”,“1-8254”)
),
[/php]

I left this out. This is at the top of the php document before the array and it may be important.
[php]

<?php class DOGS { public $site; public $degrees; public $director; public $email; public $phone; public $department; public function __construct($p_site, $p_degrees, $p_director, $p_email, $p_phone, $p_department){ $this->site = $p_site; $this->degrees = $p_degrees; $this->director = $p_director; $this->email = $p_email; $this->phone = $p_phone; $this->department = $p_department; } } class DEPT { public $contact; public $address; public $phone; public function __construct($p_address, $p_contact, $p_phone){ $this->contact = $p_contact; $this->address = $p_address; $this->phone = $p_phone; } } [/php]

[php] public function getDirector(){
return $this->director;
}
[/php]

[php]foreach ($dogs as $key => $value){
array_push($labelArray, $key.": ".$value->getDirector());
}
[/php]

[php] function showOptionsDrop($array, $active, $echo=true){
foreach($array as $k => $v){
if(is_array($active))
$s = (in_array($k, $active))? ’ selected=“selected”’ : ‘’;
else
$s = ($active == $k)? ’ selected=“selected”’ : ‘’;
$string .= ‘<option value="’.$k.’"’.$s.’>’.$v.’’."\n";
}
if($echo) echo $string;
else return $string;
}
[/php]

[php]echo showOptionsDrop($labelArray, $chosen, true);
[/php]

[php]<?php
require_once(“dogs.php”);
echo “

”;
print_r($dogs);
echo “
”;
?>[/php]

[php]<?php
require_once(“dogs.php”);
foreach ($dogs as $key => $value) {
echo “

”;

print_r($dogs);

	print_r($key);
	echo "<br/>";
	print_r($value);
	echo "</pre>";
}

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service