这是我的矩阵
123456 // column number
agmsy4
bhntz5
ciou06
djpv17
ekqw28
flrx39
结果列转置:
432561 // key
agmy4s
bhnz5t
cio06u
djp17v
ekq28w
flr39x
但我想要这样的结果:
432561 // key
smgy4a
tnhz5b
uoi06c
vpj17d
wqk28e
我正在使用更改功能,但结果是错误的,如何解决这个问题?
我用这个函数来改变列矩阵的位置
function exchange(&$v1, &$v2){
$temp = $v1;
$v1 = $v2;
$v2 = $temp;
}
$k=array(4,3,2,5,6,1);
$b=1;
for($s=0;$s<=5;$s++)
{
exchange($asciiT[$b], $asciiT[$k[$s]]);
$b++;
}
这是我的所有代码:
<?php
function exchange(&$v1, &$v2){
$temp = $v1;
$v1 = $v2;
$v2 = $temp;
}
$d=0;
$ascii=array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9');
for($b=1;$b<=6;$b++) {
for($c=1;$c<=6;$c++){
$asciiT[$b][$c]=$ascii[$d];
$d++;
}
}
for($b=1;$b<=6;$b++) {
for($c=1;$c<=6;$c++){
echo $asciiT[$b][$c];
}
}
for($b=1;$b<=6;$b++)
{
for($c=1;$c<=6;$c++)
{
$temp = $asciiT[$c][$b];
$asciiT[$c][$b] = $asciiT[$b][$c];
$asciiT[$b][$c] = $temp;
}
}
$k=array(4,3,2,5,6,1);
$b=1;
for($s=0;$s<=5;$s++)
{
exchange($asciiT[$b], $asciiT[$k[$s]]);
$b++;
}
echo "<br/><br/>";
for($b=1;$b<=6;$b++)
{
echo "<br/>";
for($c=1;$c<=6;$c++)
{
echo $asciiT[$c][$b];
}
}
echo "<br/><br/>";
for($b=1;$b<=6;$b++)
{
for($c=1;$c<=6;$c++)
{
echo $asciiT[$c][$b];
}
}
感谢