Quote:
Originally posted by Belisarius Wouldn't the "foreach" just get skipped if the size of the array is 0? |
Yes, it will skip the foreach. No clue if that's the desired behavior. (note the docs on sizeof/count - they work with strings, but only to return 1 if the string has data vs the amount of array slices)
So the previous example would pass the sizeof() test, but may bomb out on the foreach as sde mentions. Adding an additional check with is_array() might be wise as well. I believe Epsilon is correct about the `one checkbox` thing. Its been awhile, but I remember having to add some additional checks that detected data and if the var was an array. If it had data, but no array, then I'd have to manually assign the data to slice 0. Maybe it was an old php thing - maybe not.
To be as clean as sde's example, you may have to do something like:
PHP Code:
// create local var - its never clean to rely on register_globals
$shows = Array();
if (sizeof($_POST['shows']) > 0) {
if (is_array($_POST['shows'])) {
$shows = $_POST['shows'];
}
else {
$shows[0] = $_POST['shows'];
}
foreach ($shows as $foo) {
//bar
}
}
-r