Changeset 62524 for trunk/src/wp-includes/functions.php
- Timestamp:
- 06/18/2026 05:49:04 PM (10 hours ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/functions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r62521 r62524 5291 5291 * Determines if the variable is a numeric-indexed array. 5292 5292 * 5293 * Note! This answers a different question than {@see array_is_list()} and is 5294 * more flexible to handle situations where some numeric array indices 5295 * have been removed. A numeric-indexed array is only a “list” when the 5296 * array keys form a contiguous range from zero to the highest key. 5297 * 5298 * Example: 5299 * 5300 * true === wp_is_numeric_array( array( 1, 2, 3, 4 ) ); 5301 * false === wp_is_numeric_array( array( 'name' => 'WordPress' ) ); 5302 * 5303 * // All-numeric keys vs. list. 5304 * $above_two = array_filter( array( 1, 2, 8, 9 ), fn ( $v ) => $v > 2 ); 5305 * $above_two === array( '2' => 8, '3' => 9 ); 5306 * true === wp_is_numeric_array( $above_two ); 5307 * false === array_is_list( $above_two ); 5308 * 5293 5309 * @since 4.4.0 5294 5310 * 5295 5311 * @param mixed $data Variable to check. 5296 5312 * @return bool Whether the variable is a list. 5297 */ 5298 function wp_is_numeric_array( $data ) { 5313 * 5314 * @phpstan-assert-if-true array<int, mixed> $data 5315 */ 5316 function wp_is_numeric_array( $data ): bool { 5299 5317 if ( ! is_array( $data ) ) { 5300 5318 return false; 5301 5319 } 5302 5320 5303 $keys = array_keys( $data ); 5304 $string_keys = array_filter( $keys, 'is_string' ); 5305 5306 return count( $string_keys ) === 0; 5321 foreach ( $data as $key => $value ) { 5322 if ( is_string( $key ) ) { 5323 return false; 5324 } 5325 } 5326 5327 return true; 5307 5328 } 5308 5329
Note: See TracChangeset
for help on using the changeset viewer.