您的位置:首页 > 编程语言 > PHP开发

php练习

2016-01-14 11:40 246 查看
<?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

-->
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: