I have a form which allows the user to select different categories. Each category has a specific ID number, so a typical response would be:
"10, 7, 15, 46, 32"
and this is stored in the variable $categories.
So I obviously want to split this by the commas, I could use explode() or split() but for this example I'll use explode():
$categories = explode(",", $categories);
Now I want to get rid of the white spaces, so I'll use trim(). But, my question is, can I pass the array $categories into trim() and expect to have the white spaces stripped from each element. Or, will I have to do a while loop, extracting the white space individually from each element.
$c = 0;
$categories[$c] = trim($categories[$c]);
I believe you'll have to use the while loop. The thing to do is try it. :)
It worked (the while loop)... thanks! :)
Can's you go:
$categories = explode(", ", $categories);
So the explod() gets rid of the whitespace as well?
That would work fine as long as the user added a space after every comma. I thought about the setup I was running, it's much too complicated for the user to use. I'm going to change it so that an array of checkboxes is displayed, then the user will be able to check each category the image should belong to instead of remembering each Category ID.