wp_recursive_ksort() WordPress Function

The wp_recursive_ksort() function sorts an array or object recursively by key. This is a useful function for sorting large multidimensional arrays by key, such as those used in Wordpress themes and plugins.

wp_recursive_ksort( array $array ) #

Sorts the keys of an array alphabetically.


Description

The array is passed by reference so it doesn’t get returned which mimics the behaviour of ksort.


Top ↑

Parameters

$array

(array)(Required)The array to sort, passed by reference.


Top ↑

Source

File: wp-includes/functions.php

function wp_recursive_ksort( &$array ) {
	foreach ( $array as &$value ) {
		if ( is_array( $value ) ) {
			wp_recursive_ksort( $value );
		}
	}
	ksort( $array );
}


Top ↑

Changelog

Changelog
VersionDescription
6.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More