0

I make a function for put in an array all php variable in a file (.php)

In the array, I want something like this:

$myvariable = 'hello man';

So I do:

$myarray['$variable'] = $variable;

For have:

array('$myvariable' => 'hello man', '$othervariable' => 'in the space...');

I want "print" the array like this:

 foreach($myarray as $key =>$value){
    echo $key.' -> '.$value.'<br>';
 }

When I do:

$myarray['$variable'] = $variable;
$myarray["$variable"] = $variable; //don't work because "
$myarray[$variable]   = $variable; //the key is change in value

don't stay as the variable name but as the value.

How to have the variable name as string??

Amazone
  • 426
  • 4
  • 14
  • Why are you quoting the variable in the first place? Just use `$myarray[$variable]`. – Barmar Aug 17 '16 at 17:37
  • 1
    I _think_ what you're looking for is `array('\$myvariable' => 'hello man', ... );` and `$myarray['\$variable'] = $variable;` – jonhopkins Aug 17 '16 at 17:39

0 Answers0