note 124607 added to function.compact
| From: | lekiagospelatgmaildotcom@php.net | Date: | Mon, 13 Jan 2020 13:20:43 +0000 |
| Subject: | note 124607 added to function.compact | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-213873@lists.php.net to get a copy of this message | ||
Consider these two examples. The first as used in the manual, and the second a slight variation of
it.
Example #1
<?php
$city = "San Francisco";
$state = "CA";
$event = "SIGGRAPH";
$location_vars = array("city", "state");
$result = compact("event", $location_vars);
print_r($result);
?>
Example #1 above will output:
Array
(
[event] => SIGGRAPH
[city] => San Francisco
[state] => CA
)
Example #2
<?php
$city = "San Francisco";
$state = "CA";
$event = "SIGGRAPH";
$location_vars = array("city", "state");
$result = compact("event", "location_vars");
print_r($result);
?>
Example #2 above will output:
Array
(
[event] => SIGGRAPH
[location_vars] => Array
(
[0] => city
[1] => state
)
)
In the first example, the value of the variable $location_values (which is an array containing city,
and state) is passed to compact().
In the second example, the name of the variable $location_vars (i.e without the '$'
sign) is passed to compact() as a string. I hope this further clarifies the points made in the
manual?
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.168 (proxied: 41.223.64.194)
----
Manual Page -- http://php.net/manual/en/function.compact.php
Edit -- https://master.php.net/note/edit/124607
Del: integrated -- https://master.php.net/note/delete/124607/integrated
Del: useless -- https://master.php.net/note/delete/124607/useless
Del: bad code -- https://master.php.net/note/delete/124607/bad+code
Del: spam -- https://master.php.net/note/delete/124607/spam
Del: non-english -- https://master.php.net/note/delete/124607/non-english
Del: in docs -- https://master.php.net/note/delete/124607/in+docs
Del: other reasons-- https://master.php.net/note/delete/124607
Reject -- https://master.php.net/note/reject/124607
Search -- https://master.php.net/manage/user-notes.php