Php retrieves the largest number of numeric strings and sorts them again

Source: Internet
Author: User
(1) enter a number string to find the maximum number. For example, enter 17893 and the maximum number is 9. (2) sort the five numbers... For example, in the preceding example, the result is 98731;

(1) enter a number string to find the maximum number. For example, enter 17893, and the maximum number is 9;
(2) sort these five numbers... For example, in the preceding example, the result is 98731;

$ Num = "17892"; // initial value. you can use $ _ POST [] to obtain the value submitted by the form.
$ Len = strlen ($ num); // get the length
$ Tmp = ""; // initialize $ tmp


/* Use-to split $ num as follows */
For ($ I = 0; $ I <$ len; $ I ++ ){
$ Tmp. = substr ($ num, $ I, 1 ).'-';
}
$ Arr = explode ('-', $ tmp); // generates an array
Rsort ($ arr); // descending order
Echo $ arr [0].'
'; // Maximum output value
Echo implode ($ arr, ''); // output the new value in descending order.
?>

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.