0

Basically, what I want is like this creating variable names from an array list

But it's the other way around, instead of creating normal variables, I want to create arrays from the variable values

2
  • What do you mean by "Create array names"? If that's not relevant, couldn't you just make an array containing the variables like you create any other array? Commented May 14, 2011 at 6:14
  • please elaborate more what u exact want: write your desired array and input array Commented May 14, 2011 at 6:17

1 Answer 1

3

If you want to make an array which maps variable names to their values, use compact(), passing variable names as strings:

$one = 1;
$two = 2;

$variables = compact('one', 'two'); // Array ( [one] => 1, [two] => 2 )

If all you want is an array containing the values of your variables, just make a normal array using array() and toss your variables in:

$one = 1;
$two = 2;

$variables = array($one, $two); // Array ( [0] => 1, [1] => 2 )
Sign up to request clarification or add additional context in comments.

1 Comment

beat to me :), but does OP really want this??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.