Tools, FAQ, Tutorials:
Padding an Array with a Given Value in PHP
How To Pad an Array with the Same Value Multiple Times in PHP?
✍: 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,>>,>>,>>
⇐ Creating an Array with a Sequence in PHP
2017-01-05, ∼4026🔥, 0💬
Popular Posts:
Where to get the detailed description of the JSON.stringify() Function in JavaScript? Here is the de...
How to use "xsl-transform" Azure API Policy Statement? The "xsl-transform" Policy Statement allows y...
How to use the "send-one-way-request" Policy statement to call an extra web service for an Azure API...
How to build a PHP script to dump Azure AD 2.0 Authentication Response? If you are use the Azure-AD-...
Where to find tutorials on EPUB file format? I want to know how to create EPUB books. Here is a larg...