The thing is I have to create a 2D matrix in php where each row and column must have a key. I tried to do this but what happens is that a 2-D array is created which does not resemble a matrix. I used the following code:
$x=$row['start_id'];
$y=$row['dest_id'];
$d=$row['distance'];
$this->map[$x][$y]=$d;
Here map is the intended matrix. The intention of this code is to create an adjacency matrix and then fill the unset cells with maximum distance. $x, $y and $d in above code are derived from result of a mysql query.
Sample Output:
Array (
[10010012] => Array (
[10010013] => 2
[10010016] => 8
)
[10010016] => Array (
[10010015] => 5
)
[10010013] => Array (
[10010014] => 7
[10010016] => 3
)
[10010014] => Array (
[10010015] => 2
)
)
Now the problem is that I am not able to fill the empty cells
e.g. row key =>[10010012] and column key=>[10010015] (Not able to set value)
Any help is appreciated. If possible also mention how to traverse through such matrices.
I am a relative beginner and have tried my best to explain my problem. However if you find any shortcomings please point them out.
Edit: The matrix is not a square one.