Code implementation PHP array sorting _php tutorial

Source: Internet
Author: User
PHP after a long period of development, many users are very familiar with PHP, here I publish a personal understanding of the PHP array sorting, and we discuss the discussion. PHP is a server-side scripting language that is easy to learn and use. With minimal programming knowledge, you can use PHP to build a truly interactive web site. This tutorial does not want you to fully understand the language, but it will allow you to join the development of dynamic Web sites as soon as possible. I assume you have some basic knowledge of HTML (or HTML editor) and some programming ideas.

PHP Web files are treated as normal HTML Web files and you can write PHP in the usual way of editing HTML when editing. PHP representative: Hypertext Preprocessor (Php:hypertext preprocessor). PHP is completely free of charge and you can download it freely from the official PHP site (http://www.php.net). PHP complies with the GNU Public License (GPL), under which many popular software such as Linux and Emacs have been created. You can gain unlimited access to the source code and even add the features you need. PHP works on most Unix platforms, Gun/linux and Microsoft Windows platforms. Having said so much, let's talk about the ordering of PHP arrays.

PHP Array Sorting code:

 
 
  1. php
  2. $ arr = Array (5=>"Zero",3=>"One", 4=>"one");//define an array
  3. Sort ($arr);//Use sort to sort array
  4. foreach ($arras $key=>$value)//Iterate through the array to view the sorted results
  5. {
  6. echo "Key: $key; Value: $value; ";
  7. }
  8. ?>
  9. php
  10. Define an array
  11. $ arr = Array (5=>"Zero",3=> "One", 4 = > "both");
  12. Using Rsort to sort arrays
  13. Rsort ($arr);
  14. Iterating an array to see the sorted results
  15. foreach ($arras $key=>$value) {
  16. echo "Key: $key; Value: $value; ";
  17. }
  18. ?>
  19. php
  20. Define 2 arrays
  21. $ ar1 = Array (5=>"Zero",3=>"One", 4=>"both");
  22. $ ar2 = Array (4=>"Three",9=> "Four", 1 = > "Five");
  23. Sorting an array
  24. Array_multisort ($ar 1, $ar 2);
  25. Iterating an array to see the sorted results
  26. foreach ($ar 1as$key=>$value) {
  27. echo "Key: $key; Value: $value; ";
  28. }
  29. echo " <BR> ";
  30. foreach ($ar 2as$key=>$value) {
  31. echo "Key: $key; Value: $value; ";
  32. }
  33. ?>
  34. php
  35. Define a two-dimensional array
  36. $ Array Array =array ("ar1" =>Array (5=>, 3 = > , 4 = > ),
  37. "AR2" = > Array (4=>"Three",9=>" Four ",1=>" Five "));
  38. Sorting an array
  39. Array_multisort ($array ["Ar1"],sort_numeric,sort_desc,
  40. $array ["Ar2"],SORT_STRING,SORT_ASC);
  41. Iterating an array to see the sorted results
  42. foreach ($arrayas $v1)
  43. {
  44. foreach ($v 1as$v2)
  45. {
  46. echo "$v 2n";
  47. }
  48. }
  49. ?>


http://www.bkjia.com/PHPjc/446536.html www.bkjia.com true http://www.bkjia.com/PHPjc/446536.html techarticle PHP After a long period of development, many users are very familiar with PHP, here I publish a personal understanding of the PHP array sorting, and we discuss the discussion. PHP is an easy to learn and use server ...

  • 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.