public function transpose() { $result = new Matrix($this->columns, $this->rows); for ($r = 0; $r < $this->rows; ++$r) { for ($c = 0; $c < $this->columns; ++$c) { $result->setElement($c, $r, $this->matrix[$r][$c]); } } return $result; }