[PHP-users 28805] 難しいソートについて
reima
reima @ wolfs.jp
2006年 3月 24日 (金) 12:49:00 JST
$B$O$8$a$^$7$F!"%=!<%H$K$D$$$F$*J9$-$7$?$$$3$H$,$"$j$^$9!#(B
$BEPO?HV9f$O(B0$B$+$i;O$^$k?t;z!"%l%Y%k$K$O!V>e!'(B1 $BCf!'(B2 $B2<!'(B3 $BIa!'(B0$B!W$NCM$,F~$C$F$$$^$9!#(B
*$B$K$O$=$N$[$+%=!<%H$K4X78$N$J$$%G!<%?$,$"$j$^$9!#(B
$BEPO?HV9f(B<>(IZM^Y(B<>UNIX$B%?%$%`%9%?%s%W(B<>*<>*<>*<>*<>*<>*<>*<>*<>*<>*<>*<>*<>*<>*<>*<>*<>*<>*<>*<>\n
$B$3$N$h$&$J%m%0$r(B $B%l%Y%k!d%l%Y%k$,!VIaDL!W$G(BUNIX$B%?%$%`$,?7$7$$$[$&$,>e!J>e!&Cf!&2<$h$j2<!K$KMh$k$h$&$K$7$?$$$N$G$9(B
$BM}A[$J%=!<%H7k2L(B
0<>1<>1111111111<>$BJ8;z(B<>$B>JN,(B...
3<>2<>1111111114<>$BJ8;z(B<>$B>JN,(B...
5<>2<>1111111116<>$BJ8;z(B<>$B>JN,(B...
6<>3<>1111111117<>$BJ8;z(B<>$B>JN,(B...
1<>0<>1111111112<>$BJ8;z(B<>$B>JN,(B...
2<>0<>1111111113<>$BJ8;z(B<>$B>JN,(B...
4<>0<>1111111115<>$BJ8;z(B<>$B>JN,(B...
http://ns1.php.gr.jp/pipermail/php-users/2002-June/007909.html
$B$G;29M$K$5$;$F$$$?$@$$$?$b$N$r(B
function compare($a, $b) {
$sa = split("<>", $a);
$sb = split("<>", $b);
if ($sa[1] == $sb[1]) return 0;
return ($sa[1] > $sb[1]) ? -1 : 1;
}
function log_sort($sdata){
usort($sdata,compare);
foreach($sdata as $key => $val){
$new_data[]=$val;
}
return $new_data;
}
$log_file="./data/log.dat";
$lines = file($log_file);
$out_data = log_sort($lines);
$fp = fopen($log_file,"w");
flock($fp,2);
fputs($fp,$out_data);
fclose($fp);
$B$N$h$&$KJQ$($F$b$&$^$/$$$+$:!&!&!&(B
$BNI$$0F$O$4$6$$$^$;$s$G$7$g$&$+!)(B
PHP$B4D6-(B
OS:Windows 2000 Pro Sp4
Web:Apache2.0.5.4
PHP:5.1.2
PHP-users メーリングリストの案内