array_pad

FunctionParams and return types changed in PHP 8.0

Pad array to the specified length with a value.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

array_pad Function synopsis

array_pad(
    array $array,
    int $length,
    mixed $value
  ): array

Parameters

$array

Typearray

Initial array of values to pad.

$length

Typeint

New size of the array.

$value

Typemixed

Value to pad if $array is less than $length.

Return value

Typearray

Returns a copy of the $array padded to size specified by $length with value $value. If $length is positive then the array is padded on the right, if it's negative then on the left. If the absolute value of $length is less than or equal to the length of the $array then no padding takes place.

Changes to the array_pad Function

PHP 8.0

  • Return type added: array
  • Parameter name of parameter #1 changed: $arg to $array
  • Parameter type added for parameter #1 ($array): array
  • Parameter name of parameter #2 changed: $pad_size to $length
  • Parameter type added for parameter #2 ($length): int
  • Parameter name of parameter #3 changed: $pad_value to $value
  • Parameter type added for parameter #3 ($value): mixed
  array_pad(
-     $arg,
+     array $array,
-     $pad_size,
+     int $length,
-     $pad_value
+     mixed $value
-   )
+   ): array

array_pad Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes