• PHP Video Tutorials

PHP - Function array_pad()



Syntax

array_pad ( $array, $pad_size, $pad_value );

Definition and Usage

It returns a copy of the array padded to size specified by pad_size with value pad_value.

Parameters

Sr.No Parameter & Description
1

array(Required)

It specifies an array.

2

pad_size(Required)

It specifies the number of elements in the array returned from the function.

3

pad_value(Required)

It specifies the value of the new elements in the array returned from the function.

Return Values

It returns the resulting array.

Example

Try out following example −

<?php
   $input1 = array("a"=>"Horse","b"=>"Cat","c"=>"Dog");
   
   print_r(array_pad($input1,7, "COW"));
?> 

This will produce the following result −

Array ( [a] => Horse [b] => Cat [c] => Dog [0] => COW [1] => COW [2] => COW [3] => COW )
php_function_reference.htm
Advertisements