I have a variable that is dynamic and updates once every day from a cache file, but when I wish to display the variable it pulls nothing although my cache file has the information stored.
This is an example of what I am trying to do…
$var1 = "1"; // Dynamic info that is previously pulled from the cache file.
$var2 = array (
"0" => "2",
"1" => "3" );
Now I want to display the content of a certain part of the array…
echo "Test ".$var2['$var1'];
This is meant to output: Test 3
And if $var1 was a 0 it would output: Test 2
I have tried this many other ways, including changing the ‘ to “, or not even including them, it either displays a PHP error or it displays nothing apart from the “Test” text.
EDIT#1:
Ok, so this is to explain what I am doing a little bit better.
First I pull from a file and replace anything that comes with it that I don’t need..
$myFile = "http://someserver.com/afile.txt";
$lines = file($myFile);
$ngender = preg_replace('/Gender=/', '', $lines[3]);
Now, I know that the above code works fine, its when I get to the array that I have problems..
$ngen = array (
1 => "Male",
2 => "Female"
);
Then I use $ngen[$ngender]; to store it into the xml file, but it don’t store anything. This is actually I am trying to do before I store it into the xml file.
It should be:
$var1 is a variable so it should no be in ”.