php练习

<?php

function bubble_sort(& $arr){
$number=count($arr);
for($i=0;$i<$number-1;$i++){
for($j=0;$j<$number-1-$i;$j++){
   if($arr[$j]>$arr[$j+1]){
    $tmp=$arr[$j];
    $arr[$j]=$arr[$j+1];
    $arr[$j+1]=$tmp;
   }
}
}
}

$str="10 2 36 14 10 25 23 85 99 45";
$arr=explode(" ",$str);
bubble_sort($arr);
echo "<pre>";
var_dump($arr);

?>

<!--
输出结果
array(10) {
  [0]=>
  string(1) "2"
  [1]=>
  string(2) "10"
  [2]=>
  string(2) "10"
  [3]=>
  string(2) "14"
  [4]=>
  string(2) "23"
  [5]=>
  string(2) "25"
  [6]=>
  string(2) "36"
  [7]=>
  string(2) "45"
  [8]=>
  string(2) "85"
  [9]=>
  string(2) "99"
}

-->

获取指定的文件

<?php

//$d = dir(dirname(php_session));
$d = dir(dirname(htdocs));
//echo "Handle: " . $d->handle . "\n";
//echo "Path: " . $d->path . "\n";
while ( false !== ($entry = $d->read ()) ) {
echo $entry . "<br />";
}
$d->close ();

?>

<!--

bubble_sort.php
bubble_sort.php.bak
dir_file.php
dir_file.php.bak
page1.php
page2.php
page3.php

-->
时间: 2024-10-20 16:46:39