Page 2 of 2

Posted: Sun Feb 25, 2007 2:00 pm
by montyauto
feyd wrote:Standard variables cannot be two, separate words (by spaces.) You need to look at arrays more or variable variables.
I have been looking from both array & variable variables
still found no way to get string from variable..

Posted: Sun Feb 25, 2007 2:04 pm
by Ambush Commander
You would set up array keys, and then output the array key as the variable name and $array[$array_key] for the value.

Posted: Sun Feb 25, 2007 2:14 pm
by montyauto
Ambush Commander wrote:You would set up array keys, and then output the array key as the variable name and $array[$array_key] for the value.
I can't get it, still blank idea..
would you pls show me that way with the code?

Posted: Sun Feb 25, 2007 2:17 pm
by Ambush Commander

Code: Select all

$person['name'] = 'John';
$person['favorite color'] = 'gold';
print 'hey friend, ';
foreach ($person as $property => $value) {
  print "his $property is $value, ";
}

Posted: Sun Feb 25, 2007 2:33 pm
by montyauto
Ambush Commander wrote:

Code: Select all

$person['name'] = 'John';
$person['favorite color'] = 'gold';
print 'hey friend, ';
foreach ($person as $property => $value) {
  print "his $property is $value, ";
}

thanks now I get what you mean

but, again, I need to write in the code:

Code: Select all

$myvar = 42;


not

Code: Select all

$something["myvar"] = 42;

Posted: Sun Feb 25, 2007 2:38 pm
by feyd
It's not going to happen. Why do you need this so specifically? What's the actual case you are dealing with?

Posted: Sun Feb 25, 2007 2:50 pm
by Ambush Commander
Try...

Code: Select all

$vars = array('name', 'age');
$something = compact($vars);
$something is now an array you can iterate over.

Posted: Sun Feb 25, 2007 3:56 pm
by montyauto
Finaly I just get the answer.

Posted: Sun Feb 25, 2007 4:04 pm
by Ambush Commander
I seriously do not think this is the way you should be going about doing this. You've possibly introduced a security vulnerability and the code won't make much sense to other people.

Posted: Sun Feb 25, 2007 4:07 pm
by volka
second thread on same topic.
see viewtopic.php?t=62067

Posted: Sun Feb 25, 2007 4:17 pm
by montyauto
Ambush Commander wrote:I seriously do not think this is the way you should be going about doing this. You've possibly introduced a security vulnerability and the code won't make much sense to other people.
If it is the case then I should appologize.
I have edited my previous post.

Posted: Sun Feb 25, 2007 4:19 pm
by Ambush Commander
There's no need to remove the link, we're just trying to help you.