note 92166 added to language.variables.scope
| From: | akam at akameng dot com | Date: | Sun, 12 Jul 2009 14:39:46 +0000 |
| Subject: | note 92166 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158201@lists.php.net to get a copy of this message | ||
Many Times Globality of variables will be the small issue, after long time I decided to use super
globals.
Super globals exists any where:
$_SERVER, $_GET, $_POST .....
Now for example:
<?php
$foo[] = range(0, 3);
$_POST['foo'] = $foo;
a(); //no parameters needed.
b();
$foo = $_POST['foo'];
Print_r($foo);
/* out
Array
(
[0] => Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
)
[1] => Array
(
[0] => 4
[1] => 5
[2] => 6
[3] => 7
)
[2] => Array
(
[0] => 8
[1] => 9
[2] => 10
)
)
*/
function a(){
$_POST['foo'][] = range(4, 7);
}
function b(){
$_POST['foo'][] = range(8, 10);
}
?>
Note: the key must not be passed by the page via _POST method by the form, else the value will be
over written
----
Server IP: 69.147.83.197
Probable Submitter: 66.90.73.246
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/92166
Del: integrated -- https://master.php.net/note/delete/92166/integrated
Del: useless -- https://master.php.net/note/delete/92166/useless
Del: bad code -- https://master.php.net/note/delete/92166/bad+code
Del: spam -- https://master.php.net/note/delete/92166/spam
Del: non-english -- https://master.php.net/note/delete/92166/non-english
Del: in docs -- https://master.php.net/note/delete/92166/in+docs
Del: other reasons-- https://master.php.net/note/delete/92166
Reject -- https://master.php.net/note/reject/92166
Search -- https://master.php.net/manage/user-notes.php