About PHP two-dimensional array sorting using key implementation _php Tutorial

Source: Internet
Author: User
The PHP array has one-dimensional arrays and no arrays, and here we analyze the techniques of PHP's two-dimensional array ordering. PHP, a nested abbreviated name, is an abbreviation for the English Super Text preprocessing language (Php:hypertext preprocessor). PHP is an HTML embedded language, is a server-side implementation of embedded HTML document scripting language, language style has similar to the C language, is now widely used by many web site programmers. PHP's unique syntax mixes C, Java, Perl, and PHP's self-innovative syntax.

It can perform dynamic Web pages more quickly than CGI or Perl. Dynamic pages made with PHP are compared to other programming languages, and PHP is executed in an HTML document, which is much more efficient than CGI, which is also embedded in the HTML document, and PHP is executed on the server side, compared to the scripting language JavaScript Take full advantage of the performance of the server, the PHP execution engine will also be the user frequently access to the PHP program in memory, other users do not need to recompile the program once again to access the program, as long as the direct execution of in-memory code, which is the embodiment of PHP efficiency. PHP has a very powerful feature, all CGI or JavaScript functionality PHP can be implemented, and support almost all the popular database and operating system.

PHP two-dimensional array ordering uses the Asort function, but if a multidimensional array is sorted by one of the index values. In general, such a sort would introduce a temporary array to store intermediate variables such as key values by sorting the key to achieve a sort of multidimensional array. Here is a paragraph I wrote to sort by the time values in a two-dimensional array:

PHP two-dimensional array sorting code:

 
 
  1. php
  2. A two-dimensional array in descending order with the time inputdate as the key value
  3. function Array_sort ($arr, $keys, $type) {
  4. $ Keysvalue = Array ();
  5. $ I = 0 ;
  6. foreach ($arr as $key=>$val) {
  7. $val [$keys] = Str_replace ("-", "", $val [$keys]);
  8. $val [$keys] = Str_replace ("", "", $val [$keys]);
  9. $val [$keys] = Str_replace (":", "", $val [$keys]);
  10. $keysvalue [] = $val [$keys];
  11. }
  12. Asort ($keysvalue); Key value Sort
  13. Reset ($keysvalue); The pointer re-points to the first array of
  14. foreach ($keysvalue as $key=>$vals) {
  15. $keysort [] = $key;
  16. }
  17. $ New_array = Array ();
  18. if ($type! = "ASC") {
  19. For ($II=count($keysort)-1; $ii>= 0; $ ii--) {
  20. $new _array[] = $arr [$keysort [$ii]];
  21. }
  22. }else{
  23. For ($II=0; $ii<count($keysort ); $ii + +) {
  24. $new _array[] = $arr [$keysort [$ii]];
  25. }
  26. }
  27. return $new _array;
  28. }
  29. ?>

http://www.bkjia.com/PHPjc/446494.html www.bkjia.com true http://www.bkjia.com/PHPjc/446494.html techarticle the PHP array has one-dimensional arrays and no arrays, and here we analyze the techniques of PHP's two-dimensional array ordering. PHP, a nested abbreviated name, is the English Super Text preprocessing language (php:hy ...

  • Related Article

    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.