hello all, i'm having some trouble selecting information from a multidimensional array.
I'm reading in the array information from a text file, the information is formatted as so:
3 1
1 2
4 1
4 1
4 1
I build the array as so:
//get Transition Table
for ($counter = 0; $counter < $rowsTrans; $counter++)
{
$tableTrans = fgets($fp);
$tableTrans = trim($tableTrans);
//split string into array
$TransTable = explode(" ", $tableTrans);
//array into multidimensional array
$transTableArray[$counter] = $TransTable;
print_r($TransTable);
echo "<br>";
}
print_r($transTableArray);
The $rowsTrans is selected from the text file earlier and is returning the correct result.
The output of print_r($transTable Array) is:
Array ( [0] => Array ( [0] => 3 [1] => 1 ) [1] => Array ( [0] => 1 [1] => 2 ) [2] => Array ( [0] => 4 [1] => 1 ) [3] => Array ( [0] => 4 [1] => 1 ) [4] => Array ( [0] => 4 [1] => 1 ) )
Now to select the information from the array I'm doing this:
//get value from Transitional Table
$column = current( $usrStringArray);
echo "Column: $column <br>";
$row = $currentState;
echo "Row: $row <br>";
$currentState = $transTableArray[$row][$column];
echo "Test: $transTableArray[$row][$column]<br>";
echo "Results from Trans Table Inquiry (last Char): $currentState <br>";
Its output is:
Column: 0
Row: 0
Test: [0]
Why is it returning 0? I know I'm in $transTableArray[0][0] but its value should be 3...
If anyone could help me at all it would be appriciated, I'm on AIM as elmcitizen as well.
Thanks Again!