Passing Arrays in Forms

Though it may not be apparent, it is possible to pass arrays from a form. To understand how, you must recall how form fields are turned into PHP variables. Each field is read in order by PHP and turned into an assignment statement. A URL like http://www.somesite.com/script.php3?name=leon creates an assignment like $name = "leon", which means that before the script begins executing, the name variable is set.

The name of the form field is treated as the left side of an assignment statement. This means that if other special characters appear as part of the name of the field, they will interpreted accordingly. You can include square brackets to force the variable to be an array. An empty pair of square brackets will add a ...

Get Core PHP Programming: Using PHP to Build Dynamic Web Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.