添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

As in Larry's PHP book PHP 6 and MySQL 5, I have been using:

$trimmed = array_map('trim', $_POST);

to put all the $_POST[] data into an array. But there's a problem now that I'm using the checkbox input field as set to input an array like this:

<label>

<input type="checkbox" name="media[]" value="acrylic" />

acrylic

</label>

The array_map doesn't handle $_POST[] arrays

I could make each of the checkbox inputs with unique names like so:

<input type="checkbox" name="acrylic" value="acrylic" />

But an array seems in order here. What should I do??

Part 2 of this question is:

I get the error " Warning : trim() expects parameter 1 to be string, array given in /ApacheServer/ApacheDocRoot/phpPNEdevelopment/Gill/maaRegistrationForm.php on line 124"

... but it doesn't cause any problems in the running of the script, it will continue.

Is it proper to ignore the error and then handle the $_POST[media] array in whatever way I want? Or should no script be considered "good code" as long as there is an error "at large" no matter if it is benign?

That's a warning (non-fatal error) therefore script execution isn't stopped, personally I wouldn't ignore it.

Take a look at array_walk_recursive() on the php website.

I'm not sure that I want a recursive procedure to be applied to $trimmed array (though I'm not sure). I just want to get the "$trimmed = array_map('trim', $_POST);" to ignore the array variable media[] that is defined in the checkbox input field:

<input type="checkbox" name="media[]" value="acrylic" />

I'll deal with it myself in the $_POST['media'] array form.

When I do this:

$trimmed= array_walk_recursive($_POST);

$trimmed = array_map('trim', $trimmed);// thought I'd need this to do the actual trimming

or this:

$trimmed= array_walk_recursive($_POST);

The fields don't validate--

I had looked at it before but didn't get how the array items would get trimmed as in "array_map('trim', $_POST)". So I tried to integrate "array_map" into the "array_walk_recursive()" formula and overcomplicated things. However, I discovered that the array items do get trimmed anyway -though I don't know how unless it's just part of array_walk_recursive().??

So, thanks for bearing with me. I am no longer getting the " Warning : trim() expects parameter 1 to be string,..." which was my main concern.