ID: 31974
Comment by: shadda at gmail dot com
Reported By: pinhinha at gmail dot com
Status: Open
Bug Type: *Programming Data Structures
Operating System: LINUX
PHP Version: 5.0.3
New Comment:
....
....
....
You do realise, array_combine() does exactly that, right? Not to
mention that even were you using php4 there are several user comments
throughought php.net that show you how to accomplish this very thing
(And if I recall, There's a PEAR_COMPAT package that contains this
functionality.)
Previous Comments:
------------------------------------------------------------------------
[2005-02-14 20:23:31] pinhinha at gmail dot com
Description:
------------
Builds an associative array using value of previous defined vars.
It works on PHP 4.0.10
It doens't work on PHP 5.0.3
If the var names don't have "_" (underscore) in the name it works on
PHP4 AND PHP5.
Reproduce code:
---------------
function do_array() {
$new_array=array();
foreach (func_get_args() as $var) {
if (isset($GLOBALS[$var]))
$new_array[$var]=$GLOBALS[$var];
else exit("<b>Error</b>: var '<b>$var</b>' is not set.");
}
return $new_array;
}
$domain_name = "php.net";
$visit_date = date("Y-m-d");
$array = do_array("domain_name", "visit_date");
Expected result:
----------------
$array = ("domain_name" => "php.net",
"visit_date" => "2005-02-14"
);
Actual result:
--------------
Error: var 'domain_name' is not set.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=31974&edit=1