【发布时间】:2015-04-25 21:46:10
【问题描述】:
我写了这个脚本:
<?PHP
$file_handle = fopen("info.txt", "rb");
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$parts[] = explode('|', $line_of_text);
}
fclose($file_handle);
$a = $parts;
function cmp($a,$b){
return strtotime($a[8])<strtotime($b[8])?1:-1;
};
uasort($a, 'cmp');
$failas = "dinfo.txt";
$fh = fopen($failas, 'w');
for($i=0; $i<count($a); $i++){
$txt=implode('|', $a[$i]);
fwrite($fh, $txt);
}
fclose($fh);
?>
当我使用时:
print_r($a);
之后
uasort($a, 'cmp');
然后我可以看到排序的数组。但是当我使用这些命令写入文件时:
$fh=fopen($failas, 'w');
for($i=0; $i<count($a); $i++){
$txt=implode('|', $a[$i]);
fwrite($fh, $txt);
}
fclose($fh);
它显示未排序的信息,我做错了什么?
【问题讨论】:
标签: php file sorting text implode