I'm importing a product list, and each item has a department number. Each number correlates with a department, i.e.
- Handguns
- Used Handguns
- Used Long Guns
- Tasers
- Sporting Long Guns
There are 43 departments. Would I just do one long if statement like:
`<?php
if ($var = 1)
echo "Handguns";
else
if ($var = 2)
echo "Used Handguns";
etc..... ?>`
EDIT: I'm able to get an if statement like this to work:
function test($cat) {
if ($cat = 33)
echo "Clothing";
}
but using any array like this:
`$departments = [ 33 => Clothing, ];
function getDepartment($id, $departments) { echo $departments[$id]; }`
I've been unable to get that to work. I'm using wordpress and putting this in functions.php and calling the function from a plugin.
Should I just stick with a big if Statement?
2nd EDIT: Got it to work by including the array inside the function:
function getDepartment($id, $departments) {
$departments = [
"1" => "Handguns",
"2" => "Used Handguns",
"3" => "Used Long Guns",
"4" => "Tasers",
"5" => "Sporting Long Guns",
"6" => "SOTS ",
...
"41" => "Upper Receivers/Conv Kits",
"42" => "SBR Barrels and Uppers ",
"43" => "Upper/Conv Kits High Cap"
];
if (isset($departments[$id])) {
return $departments[$id];
}
return 'Uncategorized';
}
and inside wpallimport, the category call looked liked this: [getDepartment({column_4[1]})]