turning array elements into variable
Posted: Mon Aug 13, 2007 1:31 am
Hi everyone,
here is the problem I have a list of words in an array
$new = array("alpha", "beta", "gamma", "delta", "epsilon");
I want to turn these words into variables
whose values are in another array
with a 1 to 1 correspondance
$test = array(1,2,3,4,5);
so that
$alpha = 1
$beta = 2
$gamma = 3
$delta = 4
$epsilon = 5
i was trying something with references in arrays but bad things happened
here is the last code snippet
Don't laugh too hard
Any ideas or if I am going about this the wrong way what is the right way
here is the problem I have a list of words in an array
$new = array("alpha", "beta", "gamma", "delta", "epsilon");
I want to turn these words into variables
whose values are in another array
with a 1 to 1 correspondance
$test = array(1,2,3,4,5);
so that
$alpha = 1
$beta = 2
$gamma = 3
$delta = 4
$epsilon = 5
i was trying something with references in arrays but bad things happened
here is the last code snippet
Code: Select all
$test = array(1,2,3,4,5);
$new = array(&$alpha, &$beta, &$gamma, &$delta, &$epsilon);
for($i=0;$i=count($test);$i++) {
new[$i] =$test[$i];
}
echo $alpha."<BR>";
echo $beta."<BR>";
echo $gamma."<BR>";
echo $delta."<BR>";
echo $epsilon."<BR>";Any ideas or if I am going about this the wrong way what is the right way