![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
array_pad() function in PHP
The array_pad() function inserts a specified number of items, with a specified value, to an array. It returns array with new elements. If size is positive then the array is padded on the right, if it's negative then the padding is done on the left.
Syntax
array_pad(arr, size, value)
Parameters
arr − the array
size − total elements in the resultant array
value − the value to pad and it should be less than the size of arr
Return
The array_pad() function returns array with new elements. If size is positive then the array is padded on the right, if it's negative then the padding is done on the left.
Example
The following is an example −
<?php $arr = array("one","two"); print_r(array_pad($arr,4,"three")); ?>
Output
The following is the output −
Array ( [0] => one [1] => two [2] => three [3] => three )
Advertisements