$aaa = array();
$aaa[0]["color"] = "red";
$aaa[0]["image"] = "apple";
$aaa[1]["color"] = "blue";
$aaa[1]["image"] = "nasubi";
$aaa[2]["color"] = "green";
$aaa[2]["image"] = "hourensou";
$aaa[3]["color"] = "yellow";
$aaa[3]["image"] = "lemon";
print_r( $aaa ) ;
print "<br />";
$aaa = KuriageArray ( $aaa , 3,1);
print_r( $aaa ) ;
print "<br />";
function KuriageArray( $ary_input, $high, $low ) {
//high番目をlowに移動して、それ以下の順番を繰り下げる
//(降格・繰り下げはできない。すなわちhigh>=low)
$num_input = count ( $ary_input );
$ary_output = array();
for ($ixx = 0; $ixx < $low ; $ixx++) {
$ary_output [$ixx] = $ary_input [$ixx] ;
}
$ary_output [$low] = $ary_input [$high] ;
for ($ixx = $low + 1 ; $ixx < $high+1 ; $ixx++) {
$ary_output [$ixx] = $ary_input [$ixx - 1] ;
}
for ($ixx = $high + 1 ; $ixx < $num_input ; $ixx++) {
$ary_output [$ixx] = $ary_input [$ixx ] ;
}
return $ary_output;
}
↓出力---------------------------
Array
(
[0] => Array
(
[color] => red
[image] => apple
)
[1] => Array
(
[color] => blue
[image] => nasubi
)
[2] => Array
(
[color] => green
[image] => hourensou
)
[3] => Array
(
[color] => yellow
[image] => lemon
)
)
Array
(
[0] => Array
(
[color] => red
[image] => apple
)
[1] => Array
(
[color] => yellow
[image] => lemon
)
[2] => Array
(
[color] => blue
[image] => nasubi
)
[3] => Array
(
[color] => green
[image] => hourensou
)
)
昇格、入替が、順位繰り下げができている。
0 件のコメント:
コメントを投稿