REST API: Add wp_is_numeric_array helper function
The API uses this to do special operations on list responses (used for collections), so we need to detect whether an array is associative or numeric-indexed. After much discussion, the bikeshed is to be painted green and gold. See #33982. git-svn-id: https://develop.svn.wordpress.org/trunk@34927 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0f657d21cc
commit
374b39d6ba
|
@ -3176,6 +3176,24 @@ function wp_array_slice_assoc( $array, $keys ) {
|
||||||
return $slice;
|
return $slice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the variable is a numeric-indexed array.
|
||||||
|
*
|
||||||
|
* @since 4.4.0
|
||||||
|
*
|
||||||
|
* @param mixed $data Variable to check.
|
||||||
|
* @return bool Whether the variable is a list.
|
||||||
|
*/
|
||||||
|
function wp_is_numeric_array( $data ) {
|
||||||
|
if ( ! is_array( $data ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$keys = array_keys( $data );
|
||||||
|
$string_keys = array_filter( $keys, 'is_string' );
|
||||||
|
return count( $string_keys ) === 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters a list of objects, based on a set of key => value arguments.
|
* Filters a list of objects, based on a set of key => value arguments.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue