Code: Select all
$matrix = array (array (1, 2, 3),
array (4, 5, 6),
array (7, 8, 9));I was testing some code for speed and came across an interesting behavior that I am unfamiliar with. Here is the code to make the matrix:
Code: Select all
// make a big matrix to test
$matrix = array_fill(0, 400, array_fill(0, 400, 1));Problem is...
I need to be able to transpose the matrix. ie...
Code: Select all
$matrix = array (array (1, 2, 3),
array (4, 5, 6),
array (7, 8, 9));Code: Select all
$matrix = array (array (1, 4, 7),
array (2, 5, 8),
array (3, 6, 9));Code: Select all
$sizeof_matrix = sizeof($matrix);
$transposed_matrix = array();
for ($i = 0; $i < $sizeof_matrix; $i++) {
for ($j = 0; $j < $sizeof_matrix; $j++) {
$transposed_matrixї$j]ї$i] = $matrixї$i]ї$j];
}
}But... when I went to use it the script would just die. No errors, just a browser message that it couldn't get any data for the page. I traced the problem back to this transposition.
If I run the multi-dimensional array print function on $transposed_matrix, I get strange results. I get a 347x400 array, where the 347th row has no elements. I tried it on a different server, and got similar but different results. I got a 342x400 array, where the 342nd row had 258 elements.
I'm a bit confused as to what's happening. Any thoughts on what's going on here?
peace
mystery toast