开发者

2D Rotation Array

I need help converting this code from this thread: How to Rotate a 2D Array of Integers

to开发者_如何学Go PHP arrays.

int [,] newArray = new int[4,4];


for (int i=3;i>=0;--i) {
    for (int j=0;j<4;++j) {
        newArray[j,3-i] = array[i,j];
    }
}

Also, will this code work if the blocks are off-center?


Without putting any thought into this at all, "jagged arrays" are pretty much identical to "rectangular arrays" (which PHP doesn't support), so use em:

$newArray = array(array())

for($i=3; $i >= 0; --$i) {
    for($j=0; $j < 4; ++$j) {
        $newArray[$j][3-$i] = $oldArray[$i][$j];
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜