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] 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]