I have homework to do this program in PHP, that take a matrix and the keywords, so it can find them in the matrix diagonally: So this is how the first matrix looks, there are many with different keywords, here for instance keywords are “beef” and “pork”. So I made a program for an input that looks like these 2
Tag: matrix
PHP rotate matrix counter-clockwise
I am solving a larger problem and at one step I need to rotate a 2D array counter-clockwise. So if I have this matrix: After the rotation it will be: I have found a solution to rotate it clockwise: The thing is that this has to work even when a is uni-dimensional or has only one element. So, 1 2
Transpose 2d array, join second level with commas, and join first level with pipes
I have the following two-dimensional array: I want to convert columns to rows then reduce the matrix to a string like the following: Answer I’m assuming that you have this array: In which case, you can do this: See it working