WordPress.org

Make WordPress Core

Changeset 34927


Ignore:
Timestamp:
10/08/2015 02:13:02 AM (3 years ago)
Author:
rmccue
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r34926 r34927  
    31783178
    31793179/**
     3180 * Determines if the variable is a numeric-indexed array.
     3181 *
     3182 * @since 4.4.0
     3183 *
     3184 * @param mixed $data Variable to check.
     3185 * @return bool Whether the variable is a list.
     3186 */
     3187function wp_is_numeric_array( $data ) {
     3188    if ( ! is_array( $data ) ) {
     3189        return false;
     3190    }
     3191
     3192    $keys = array_keys( $data );
     3193    $string_keys = array_filter( $keys, 'is_string' );
     3194    return count( $string_keys ) === 0;
     3195}
     3196
     3197/**
    31803198 * Filters a list of objects, based on a set of key => value arguments.
    31813199 *
Note: See TracChangeset for help on using the changeset viewer.