(in PHP) Here is my problem, I would like to initialize an array in my class, have the constructor fill it, and then I can use the array's variables in other functions.. when I echo my array in the constructor it works perfectly, but the moment i try to echo it in another function, it gives me something very different.
class myProblem
{
public $phaseArray;
function myProblem()
{
$count1 = 0;
$metaFile = fopen( 'MyFile.txt', 'r' ) or exit( "Unable to open file!" );
while( !feof( $metaFile ) )
{
$this->phaseArray[0][$count1] = 0;
$this->phaseArray[1][$count1] = fgets( $metaFile );
echo $this->phaseArray[1][$count1], $count1, '</br>'; //this part displays well
$count1++;
}
close( $metaFile );
}
function displayError()
{
foreach( $this->phaseArray as $key => $value )
{
echo $key, $value, '</br>'; //this part does not show up correctly
}
echo $this->phaseArray[0][2]; //this part does not show up correctly
echo $this->phaseArray[1][1]; //this part does not show up correctly
}
}
Sorry about the indentation, I could not get it to work. The correct print out is(from the constructor); 0Apple 1Orange 3Pear 4Strawberry
but the second function displays; 0Array 1Array
0Array 0Array
any thoughts on what I am doing wrong? Thankyou for your time!