PHP ile Sıralama Değiştirme ? |
4 Mesajlar | 1.608 Okunma |
unction tr_strcmp ( $a , $b ) {
$lcases = array( 'a' , 'b' , 'c' , 'ç' , 'd' , 'e' , 'f' , 'g' , 'ğ' , 'h' , 'ı' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'ö' , 'p' , 'q' , 'r' , 's' , 'ş' , 't' , 'u' , 'ü' , 'w' , 'v' , 'y' , 'z' );
$ucases = array ( 'A' , 'B' , 'C' , 'Ç' , 'D' , 'E' , 'F' , 'G' , 'Ğ' , 'H' , 'I' , 'İ' , 'J' , 'K' , 'L' , 'M' , 'N' , 'O' , 'Ö' , 'P' , 'Q' , 'R' , 'S' , 'Ş' , 'T' , 'U' , 'Ü' , 'W' , 'V' , 'Y' , 'Z' );
$am = mb_strlen ( $a , 'UTF-8' );
$bm = mb_strlen ( $b , 'UTF-8' );
$maxlen = $am > $bm ? $bm : $am;
for ( $ai = 0; $ai < $maxlen; $ai++ ) {
$aa = mb_substr ( $a , $ai , 1 , 'UTF-8' );
$ba = mb_substr ( $b , $ai , 1 , 'UTF-8' );
if ( $aa != $ba ) {
$apos = in_array ( $aa , $lcases ) ? array_search ( $aa , $lcases ) : array_search ( $aa , $ucases );
$bpos = in_array ( $ba , $lcases ) ? array_search ( $ba , $lcases ) : array_search ( $ba , $ucases );
if ( $apos !== $bpos ) {
return $apos > $bpos ? 1 : -1;
}
}
}
return 0;
}
$dizi = array('Adem', 'İlkay', 'Işık', 'Ömer', 'Orhan', 'Ceren', 'Çağla', 'Zeynep');
usort($dizi, 'tr_strcmp');
var_dump($dizi);