note 75767 added to language.variables.variable
| From: | AKAM at osu1 dot php dot net | Date: | Thu, 14 Jun 2007 22:37:51 +0000 |
| Subject: | note 75767 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127488@lists.php.net to get a copy of this message | ||
It's so good to shorten the code
example:
if you use this simple form:
-------------------------
<form action="" method="post">
Name: <input type="text" name="name" /><br />
Email: <input type="text" name="email" /><br />
Comment: <input type="text" name="comment" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
The variable name are: name, email, comment
so we need to defyne them by
$name=$_POST['name'];
$email=$_POST['email'];
but by using the below code, you not need that:
<?php
foreach($_POST as $key=>$value){
$$key=$value;
}
/*
Not need to use $var=$_POST['var'] or $var=$_GET['var']
because the $_POST are an array like
array($key=>$key, ---)
*/
// test and out put results
echo "name=$name<br>email=$email<br>comment=$comment";
/*
but if you are trying to out put some variables that not exist in the form you will be fale!
*/
?>
----
Server IP: 69.39.81.135
Probable Submitter: 207.226.41.26 (proxied: 207.226.41.26)
----
Manual Page -- http://www.php.net/manual/en/language.variables.variable.php
Edit -- https://master.php.net/note/edit/75767
Del: integrated -- https://master.php.net/note/delete/75767/integrated
Del: useless -- https://master.php.net/note/delete/75767/useless
Del: bad code -- https://master.php.net/note/delete/75767/bad+code
Del: spam -- https://master.php.net/note/delete/75767/spam
Del: non-english -- https://master.php.net/note/delete/75767/non-english
Del: in docs -- https://master.php.net/note/delete/75767/in+docs
Del: other reasons-- https://master.php.net/note/delete/75767
Reject -- https://master.php.net/note/reject/75767
Search -- https://master.php.net/manage/user-notes.php