note 18310 added to language.types.array
| From: | andrew at majiclab dot ab dot ca | Date: | Thu, 17 Jan 2002 23:29:23 +0000 |
| Subject: | note 18310 added to language.types.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-25007@lists.php.net to get a copy of this message | ||
In addition to some of the notes already given, I have found the following very useful! In an HTML
form, you can use arrays:
<input type=text name=MyArray[]>
However, a more useful application would be like this:
<input type=text name=MyArray[Settings][Name]>
<input type=text name=MyArray[Settings][Age]>
<input type=text name=MyArray[Prefrences][Color]>
And so on. PHP will parse it all properly for you. You can have as many dimensions to the array as
you would like, I suppose. Another good reason that this works well:
foreach( $MyArray[ 'Settings' ] as $Param => $Value )
@eval( "\$this->$Param = \"$Value\";" );
That will go through all the parameters for settings and assign to the $this object. This is useful
if you are using sessions, and you have an object defined as a session variable, like user. Then
you can just run $User->LoadFormParams() and run the loop above, and your settings are all put
into the object!!!
Hope this gives some of you some crazy ideas!!
-Andrew "Percy" Hanna
--
http://www.php.net/manual/en/language.types.array.php
http://master.php.net/manage/user-notes.php?action=edit+18310
http://master.php.net/manage/user-notes.php?action=delete+18310
http://master.php.net/manage/user-notes.php?action=reject+18310