PHP Digital alphabet Mixed Sort ____php

Source: Internet
Author: User

In order to meet the needs of a project, wrote a digital letter mixed sorting Function! Not very concise, but can make a reference.

/** * Numeric string comparison function * * @param <type> $f _CP * @param <type> $l _CP * @return <type>/Function cmp ($f _
    CP, $l _CP) {$f _CP = Strtoupper ($f _cp);

    $l _CP = strtoupper ($l _cp);
    $f _cp_ary = str_split ($f _cp);

    $l _cp_ary = str_split ($l _cp);
    $f _len = count ($f _cp_ary);

    $l _len = count ($l _cp_ary);
        foreach ($f _cp_ary as $index => $char) {$l _tmp_char = isset ($l _cp_ary[$index])? $l _cp_ary[$index]: null;

        if (Is_null ($l _tmp_char)) return 1;

        if ($char = = $l _cp_ary[$index]) continue; if (Isnumber ($char) && isnumber ($l _cp_ary[$index))//processing 2 is a special case of numbers until the back one is not a number {$f _nber = Getar
            Raycurrindexafterallnumber ($f _cp_ary, $index);

            $l _nber = Getarraycurrindexafterallnumber ($l _cp_ary, $index); Return ($f _nber < $l _nber)?
        -1:1;
        } $ord _f = Ord ($char);

        $ord _l = Ord ($l _cp_ary[$index]);
    Return ($ord _f-$ord _l);
return 0;
}
/** * Whether digital, ASCII comparison * * @param <type> $char * @return <type>/function Isnumber ($char) {$ASC _numbe

    R = Ord ($char);
    if ($asc _number >= && $asc <=) return true;
return false; /** * Whether alphabetic, ASCII comparison * * @param <type> $char * @return <type>/function Isletter ($char) {if empty    ($char))
    return false;

    $asc _letter = ord ($char);
    if ($asc _letter >= && $asc _letter <=122) return true;
return false; /** * Gets a continuous number * * @param array $ary * @param <type> $curr _index * @return <type>/function GetArray
    Currindexafterallnumber (array $ary, $curr _index) {$is _number = true;

    $index = $curr _index;
    $ret _number = Array ();  while ($is _number) {$number = Isset ($ary [$index])?
        $ary [$index]: ';
            if (!isnumber ($number)) {$is _number = false;
        Break
        } $ret _number[] = $number;
    + + $index;} $ret = ';
    if (!empty ($ret _number)) $ret = Implode (', $ret _number);
return (int) $ret; }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.