array array_pad ( array $arr, int $size , mixed $value )
引數說明:<?php $arr = array(12, 10, 9); $result = array_pad($arr, 5, 0); //從陣列右側開始, 用0填補陣列到含有5個元素 print_r($result); $result = array_pad($arr, -7, -1); //從陣列左側開始, 用-1填補陣列到含有7個元素 print_r($result); $result = array_pad($arr, 2, "noop"); // 第二個引數小於陣列長度, 不填補 print_r($result); ?>執行結果:
Array
(
[0] => 12
[1] => 10
[2] => 9
[3] => 0
[4] => 0
)
Array
(
[0] => -1
[1] => -1
[2] => -1
[3] => -1
[4] => 12
[5] => 10
[6] => 9
)
Array
(
[0] => 12
[1] => 10
[2] => 9
)