Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Pad an Array with the Same Value Multiple Times
How To Pad an Array with the Same Value Multiple Times? - PHP Script Tips - PHP Built-in Functions for Arrays
✍: FYIcenter.com
If you want to add the same value multiple times to the end or beginning of an array, you can use the array_pad($array, $new_size, $value) function. If the second argument, $new_size, is positive, it will pad to the end of the array. If negative, it will pad to the beginning of the array. If the absolute value of $new_size if not greater than the current size of the array, no padding takes place. Here is a PHP script on how to use array_pad():
<?php
$array = array("Zero"=>"PHP", "One"=>"Perl", "Two"=>"Java");
$array = array_pad($array, 6, ">>");
$array = array_pad($array, -8, "---");
print("Padded:\n");
print(join(",", array_values($array)));
print("\n");
?>
This script will print:
Padded: ---,---,PHP,Perl,Java,>>,>>,>>
2007-04-21, 5403👍, 0💬
Popular Posts:
Write down the equivalent pointer expression for referring the same element a[i][j][k][l]? a[i] == *...
What will be printed as the result of the operation below: main() { int x=20,y=35; x=y++ + x++; y= +...
How Can we change priority & what levels of priority are provided by Dot Net? Thread Priority ca...
What's the output of the following program? And why? #include main() { typedef union { int a; char b...
Can static variables be declared in a header file? You can't declare a static variable without defin...