Title: rest_validate_array_value_from_schema
Published: March 9, 2021
Last modified: August 20, 2026

---

# rest_validate_array_value_from_schema( mixed $value, array $args, string $param ): true|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/?output_format=md#changelog)

Validates an array value based on a schema.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/?output_format=md#parameters)󠁿

 `$value`mixedrequired

The value to validate.

`$args`arrayrequired

Schema array to use for validation.

`$param`stringrequired

The parameter name, used in error messages.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/?output_format=md#return)󠁿

 true|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)

## 󠀁[Source](https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/?output_format=md#source)󠁿

    ```php
    function rest_validate_array_value_from_schema( $value, $args, $param ) {
    	if ( ! rest_is_array( $value ) ) {
    		return new WP_Error(
    			'rest_invalid_type',
    			/* translators: 1: Parameter, 2: Type name. */
    			sprintf( __( '%1$s is not of type %2$s.' ), $param, 'array' ),
    			array( 'param' => $param )
    		);
    	}

    	$value = rest_sanitize_array( $value );

    	if ( isset( $args['items'] ) ) {
    		foreach ( $value as $index => $v ) {
    			$is_valid = rest_validate_value_from_schema( $v, $args['items'], $param . '[' . $index . ']' );
    			if ( is_wp_error( $is_valid ) ) {
    				return $is_valid;
    			}
    		}
    	}

    	if ( isset( $args['minItems'] ) && count( $value ) < $args['minItems'] ) {
    		return new WP_Error(
    			'rest_too_few_items',
    			sprintf(
    				/* translators: 1: Parameter, 2: Number. */
    				_n(
    					'%1$s must contain at least %2$s item.',
    					'%1$s must contain at least %2$s items.',
    					$args['minItems']
    				),
    				$param,
    				number_format_i18n( $args['minItems'] )
    			)
    		);
    	}

    	if ( isset( $args['maxItems'] ) && count( $value ) > $args['maxItems'] ) {
    		return new WP_Error(
    			'rest_too_many_items',
    			sprintf(
    				/* translators: 1: Parameter, 2: Number. */
    				_n(
    					'%1$s must contain at most %2$s item.',
    					'%1$s must contain at most %2$s items.',
    					$args['maxItems']
    				),
    				$param,
    				number_format_i18n( $args['maxItems'] )
    			)
    		);
    	}

    	if ( ! empty( $args['uniqueItems'] ) && ! rest_validate_array_contains_unique_items( $value ) ) {
    		/* translators: %s: Parameter. */
    		return new WP_Error( 'rest_duplicate_items', sprintf( __( '%s has duplicate items.' ), $param ) );
    	}

    	return true;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/rest-api.php#L2525)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api.php#L2525-L2584)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/?output_format=md#related)󠁿

| Uses | Description | 
| [rest_sanitize_array()](https://developer.wordpress.org/reference/functions/rest_sanitize_array/)`wp-includes/rest-api.php` |

Converts an array-like value to an array.

  | 
| [rest_validate_array_contains_unique_items()](https://developer.wordpress.org/reference/functions/rest_validate_array_contains_unique_items/)`wp-includes/rest-api.php` |

Checks if an array is made up of unique items.

  | 
| [rest_is_array()](https://developer.wordpress.org/reference/functions/rest_is_array/)`wp-includes/rest-api.php` |

Determines if a given value is array-like.

  | 
| [rest_validate_value_from_schema()](https://developer.wordpress.org/reference/functions/rest_validate_value_from_schema/)`wp-includes/rest-api.php` |

Validate a value based on a schema.

  | 
| [_n()](https://developer.wordpress.org/reference/functions/_n/)`wp-includes/l10n.php` |

Translates and retrieves the singular or plural form based on the supplied number.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [number_format_i18n()](https://developer.wordpress.org/reference/functions/number_format_i18n/)`wp-includes/functions.php` |

Converts float number to format based on the locale.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/?output_format=md#)

| Used by | Description | 
| [rest_validate_value_from_schema()](https://developer.wordpress.org/reference/functions/rest_validate_value_from_schema/)`wp-includes/rest-api.php` |

Validate a value based on a schema.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.7.0](https://developer.wordpress.org/reference/since/5.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frest_validate_array_value_from_schema%2F)
before being able to contribute a note or feedback.