PHP入門–sort ()、rsort()とasort()で配列の要素をソートする

1.sort ()
<?php
$cft_array=array(1,2,3,6,7,8,9,4,5);
sort($cft_array);
foreach($cft_array as $keys=>$value)
{
echo $keys."=>".$value."<br/>";
}
?>

実行結果:
0=>1
1=>2
2=>3
3=>4
4=>5
5=>6
6=>7
7=>8
8=>9

2.rsort()
<?php
$cft_array=array(1,2,3,6,7,8,9,4,5);
rsort($cft_array);
foreach($cft_array as $keys=>$value)
{
echo $keys."=>".$value."<br/>";
}
?>
実行結果:
0=>9
1=>8
2=>7
3=>6
4=>5
5=>4
6=>3
7=>2
8=>1

3.asort()
<?php
$cft_array=array(1,2,3,6,7,8,9,4,5);
asort($cft_array);
foreach($cft_array as $keys=>$value)
{
echo $keys."=>".$value."<br/>";
}
?>

PHP

Posted by arkgame