PHP - array_fill() 函式



語法

array array_fill ( int $start_index, int $num, mixed $value );

定義和用法

它使用value引數的值填充一個包含num個條目的陣列,鍵從start_index引數開始。

引數

序號 引數和描述
1

start_index

返回陣列的第一個索引

2

num

它包含要插入的元素數量

3

value

它包含用於填充的值

返回值

它返回填充後的陣列

示例

嘗試以下示例 -

<?php
   $input = array_fill(5, 6, 'apple');
   print_r($input);
?> 

這將產生以下結果 -

Array (
   [5] => apple
   [6] => apple
   [7] => apple
   [8] => apple
   [9] => apple
   [10] => apple
)
php_function_reference.htm
廣告