Cool, thanks for that. Quite helpful. But I think what I'm after is like a foreach(), but that will accept more than one array value. Here's what I came up with:
Code: Select all
function get_code($main, $sub){
$num_categories = array(
"060" => array("501", "502", "503", "504", "505", "506")
, "70" => array("507", "508", "509", "510")
, "80" => array("511", "512", "513", "514", "515", "516")
, "90" => array("517", "518")
, "100" => array("519", "520", "521", "522")
, "200" => array("523", "524", "525", "526")
, "300" => array("548", "549", "550", "551")
, "400" => array("527", "528", "529")
, "500" => array("530", "531", "531", "532", "533")
, "600" => array("534", "535", "536", "537", "538", "539", "540")
, "700" => array("541")
, "800" => array("542", "542", "543", "544")
, "900" => array("545", "546", "547")
);
$categories = array(
"Furniture" => array("Art", "Pictures", "Antiquities", "Item Managers", "Decoration", "Movable")
, "Family" => array("Toys", "Motherhood", "Jewels and Perfumes", "Pharmacy")
, "Tools" => array("Tools", "Heavy Equipment", "Generators", "Pro Equipment", "Rentals", "Agricultural Tools")
, "Animals" => array("Accessories", "Bedding")
, "Real Estate" => array("Commerce", "Business", "Residential", "Industrial/Machine")
, "Hardware" => array("Electrical", "Plumbing", "Electrical", "Sanitation")
, "Education" => array("Books", "Computers", "Printers/Peripherals", "School/Office Supplies")
, "Data Processing" => array("Software", "Games", "Computer Accessories")
, "Electronics" => array("Audio", "Video", "Video Game Consoles", "Phones", "Cell Phone Accessories")
, "Leisures" => array("Sports Equipment", "Photography", "Music", "Musical Instruments", "Movies", "Collections", "Hobbies")
, "Community" => array("Sharing")
, "Automobiles" => array("Directories", "Accessories", "Cars", "Equipment")
, "Employment" => array("Job Fairs", "Seminars", "Frameworks")
);
while((list($key, $value) = each($categories)) && (list($key_num, $value_num) = each($num_categories))){
echo $key.": ".$key_num."<br />";
if($key == $main){
$foo = $key_num;
}
while((list($subkey, $subvalue) = each($value)) && list($subkey2, $subvalue2) = each($value_num)){
echo "--".$subvalue.": $subvalue2<br />";
if($subvalue == $sub){
$bar = $subvalue2;
}
}
$both = $foo.": ".$bar;
return $both;
}
}
echo get_code("Furniture", "Art");
This gives me "060: 501". However, when I change the parameters, it throws an error that $foo and $bar aren't defined.
Long code, but basic basis. Any ideas on a fix?