How to use array pad in PHP
In this article, I will explain how the array_pad() function can be used in PHP.
array_pad() function in PHP
-
The array_pad() function inserts a specified number of elements, with a specified value, to an array.
-
In array_pad() function added most 1048576 elements at a time.
-
In array_pad() function, the array is padded on the right, if the specified value is positive.
-
In array_pad() function, the array is padded on the left, if the specified value is negative.
-
In array_pad() function, If the absolute value of pad size is less than or equal to the length of the input
Syntax
array_pad(array,size,value) |
Parameter
-
array array is required parameter. Specifies an array.
-
size size is required parameter. total number of padding elements in the resulting array.
-
value value is required parameter. value must be less than the size of the input array, Value will take place,.
Example
The following example show to how the array_pad() function can be used in PHP.
<html>
<body>
<h3 style="color: mediumslateblue;">array_pad() function example in PHP</h3>
<?php
$a1=array("a"=>"Student".'<br/>',"b"=>"Teacher".'<br/>',"c"=>"Engg.".'<br/>');
print_r(array_pad($a1,5, "Student".'<br/>'));
?>
</body>
</html>
|
Output

You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here