PHP array_pad()函数与示例
生活随笔
收集整理的這篇文章主要介紹了
PHP array_pad()函数与示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
PHP array_pad()函數 (PHP array_pad() function)
array_pad() function is used to pad an array to given size with a specified value and returns a new array with a specified value.
array_pad()函數用于將數組填充到具有指定值的給定大小,并返回具有指定值的新數組。
Syntax:
句法:
array_pad(array, size, value);Here,
這里,
array is an array in which we have to add the elements.
數組是我們必須在其中添加元素的數組。
size is the length/size of the array.
size是數組的長度/大小。
value is the value to be added to pad an array.
value是要填充數組的值。
Examples:
例子:
Input:$arr = array(10, 20, 30);Function call:array_pad($arr, 5, 100);Output:Array( [0] => 10 [1] => 20 [2] => 30 [3] => 100 [4] => 100 )PHP code:
PHP代碼:
<?php$arr = array(10, 20, 30);//padding to 5 elements with value 100$result = array_pad($arr, 5, 100);//printingprint_r ($result);$arr = array("Hello", "Guys");//padding to 5 elements with value "Bye!"$result = array_pad($arr, 5, "Bye!");//printingprint_r ($result); ?>Output
輸出量
Array ( [0] => 10 [1] => 20 [2] => 30 [3] => 100 [4] => 100 ) Array ( [0] => Hello[1] => Guys [2] => Bye! [3] => Bye! [4] => Bye! )翻譯自: https://www.includehelp.com/php/array_pad-function-with-example.aspx
總結
以上是生活随笔為你收集整理的PHP array_pad()函数与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php curl 关闭tcp连接,BAS
- 下一篇: 字符串大写转小写库函数_PHP程序无需使