Last active
June 10, 2023 07:34
-
-
Save rela589n/166c6d32c793daa8627aecf06d57be37 to your computer and use it in GitHub Desktop.
Transpose Matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function transposeMatrix(array $matrix): array | |
{ | |
if (1 === count($matrix)) { | |
return array_chunk(reset($matrix), 1); | |
} | |
return array_map(null, ...$matrix); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment