PHP two-dimensional array sorting

不言
Release: 2023-03-24 08:46:02
Original
1763 people have browsed it

This article introduces the two-dimensional array sorting in PHP. It has a certain reference value. Now I share it with you. Friends in need can refer to it

// $array Sorting array

// $sort_key Sorting conditions

// $sort_order Sorting method


  • #SORT_ASC - Default, sort in ascending order. (A-Z)

  • SORT_DESC - Sort in descending order. (Z-A)

// $sort_type Sort data type


  • ##SORT_REGULAR - Default. Arrange each item in regular order.

  • SORT_NUMERIC - Sort each item into numerical order.

  • SORT_STRING - Arrange each item in alphabetical order

  • my_sort($array, 'sort_time', SORT_DESC, SORT_STRING);        // 方法调用
    my_sort($arrays,$sort_key,$sort_order=SORT_ASC,$sort_type=SORT_NUMERIC ){  
    	        if(is_array($arrays)){  
    	            foreach ($arrays as $array){  
    	                if(is_array($array)){  
    	                    $key_arrays[] = $array[$sort_key];  
    	                }else{  
    	                    return false;  
    	                }  
    	            }  
    	        }else{  
    	            return false;  
    	        } 
    	        array_multisort($key_arrays,$sort_order,$sort_type,$arrays);  
    	        return $arrays;  
    	    } 
    	}
    Copy after login
Related recommendations:

php 2D Array deduplication method

PHP two-dimensional array is cut into strings and duplicate values ​​are removed

PHP two-dimensional array is converted into one-dimensional array Methods

The above is the detailed content of PHP two-dimensional array sorting. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template