HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

array_fill

Description

The array_fill of Array for PHP fills an array with values.

Syntax

array_fill(
    int $start_index,
    int $count,
    mixed $value
): array

Parameters

start_index

The first index of the returned array.

count

Number of elements to insert. Must be greater than or equal to zero, and less than or equal to 2147483647.

value

Value to use for filling

Return

Returns the filled array

Examples

1 · start_index · negative

<?

$start_index = -5;
$count = 5;
$value = "abc";

$return = array_fill($start_index, $count, $value);

print_r($return);
Array
(
    [-5] => abc
    [-4] => abc
    [-3] => abc
    [-2] => abc
    [-1] => abc
)

2 · start_index · zero

<?

$start_index = 0;
$count = 5;
$value = "abc";

$return = array_fill($start_index, $count, $value);

print_r($return);
Array
(
    [0] => abc
    [1] => abc
    [2] => abc
    [3] => abc
    [4] => abc
)

3 · start_index · positive

<?

$start_index = 5;
$count = 5;
$value = "abc";

$return = array_fill($start_index, $count, $value);

print_r($return);
Array
(
    [5] => abc
    [6] => abc
    [7] => abc
    [8] => abc
    [9] => abc
)

4 · count · zero

<?

$start_index = 0;
$count = 0;
$value = "abc";

$return = array_fill($start_index, $count, $value);

print_r($return);
Array
(
)

5 · count · positive

<?

$start_index = 0;
$count = 5;
$value = "abc";

$return = array_fill($start_index, $count, $value);

print_r($return);
Array
(
    [0] => abc
    [1] => abc
    [2] => abc
    [3] => abc
    [4] => abc
)

6 · value · boolean

<?

$start_index = 0;
$count = 5;
$value = true;

$return = array_fill($start_index, $count, $value);

print_r($return);
Array
(
    [0] => 1
    [1] => 1
    [2] => 1
    [3] => 1
    [4] => 1
)

7 · value · integer

<?

$start_index = 0;
$count = 5;
$value = 0;

$return = array_fill($start_index, $count, $value);

print_r($return);
Array
(
    [0] => 0
    [1] => 0
    [2] => 0
    [3] => 0
    [4] => 0
)

8 · value · float

<?

$start_index = 0;
$count = 5;
$value = 1.2;

$return = array_fill($start_index, $count, $value);

print_r($return);
Array
(
    [0] => 1.2
    [1] => 1.2
    [2] => 1.2
    [3] => 1.2
    [4] => 1.2
)

9 · value · string

<?

$start_index = 0;
$count = 5;
$value = "abc";

$return = array_fill($start_index, $count, $value);

print_r($return);
string(0) ""
bool(true)

10 · value · array

<?

$start_index = 0;
$count = 5;
$value = [0, 1];

$return = array_fill($start_index, $count, $value);

print_r($return);
NULL
bool(false)

bool(false)
bool(true)

bool(true)
bool(true)

int(-9223372036854775808)
bool(true)

int(9223372036854775807)
bool(true)

int(0)
bool(true)

int(1)
bool(true)

int(23)
bool(true)

int(0)
bool(true)

int(0)
bool(true)

int(-1)
bool(true)

int(1)
bool(true)

int(-23)
bool(true)

int(23)
bool(true)

int(0)
bool(true)

int(1)
bool(true)

int(19)
bool(true)

int(0)
bool(true)

int(1)
bool(true)

int(35)
bool(true)

float(0)
bool(true)

float(1.1)
bool(true)

float(23.45)
bool(true)

float(0)
bool(true)

float(10000000000)
bool(true)

float(230000000000)
bool(true)

string(0) ""
bool(true)

string(1) "0"
bool(true)

string(1) "1"
bool(true)

string(2) "23"
bool(true)

string(2) "-0"
bool(true)

string(2) "+0"
bool(true)

string(2) "-1"
bool(true)

string(2) "+1"
bool(true)

string(3) "-23"
bool(true)

string(3) "+23"
bool(true)

string(2) "00"
bool(true)

string(2) "01"
bool(true)

string(3) "023"
bool(true)

string(3) "0x0"
bool(true)

string(3) "0x1"
bool(true)

string(4) "0x23"
bool(true)

string(3) "0.0"
bool(true)

string(3) "1.1"
bool(true)

string(5) "23.45"
bool(true)

string(4) "0e10"
bool(true)

string(4) "1e10"
bool(true)

string(5) "23e10"
bool(true)

string(4) "0abc"
bool(true)

string(4) "1abc"
bool(true)

string(5) "23abc"
bool(true)

string(5) "-0abc"
bool(true)

string(5) "+0abc"
bool(true)

string(5) "-1abc"
bool(true)

string(5) "+1abc"
bool(true)

string(6) "-23abc"
bool(true)

string(6) "+23abc"
bool(true)

string(5) "00abc"
bool(true)

string(5) "01abc"
bool(true)

string(6) "023abc"
bool(true)

string(6) "0x0abc"
bool(true)

string(6) "0x1abc"
bool(true)

string(7) "0x23abc"
bool(true)

string(6) "0.0abc"
bool(true)

string(6) "1.1abc"
bool(true)

string(8) "23.45abc"
bool(true)

string(7) "0e10abc"
bool(true)

string(7) "1e10abc"
bool(true)

string(8) "23e10abc"
bool(true)

string(3) "abc"
bool(true)

string(4) "abc0"
bool(true)

string(4) "abc1"
bool(true)

string(5) "abc23"
bool(true)

string(5) "abc-0"
bool(true)

string(5) "abc+0"
bool(true)

string(5) "abc-1"
bool(true)

string(5) "abc+1"
bool(true)

string(6) "abc-23"
bool(true)

string(6) "abc+23"
bool(true)

string(5) "abc00"
bool(true)

string(5) "abc01"
bool(true)

string(6) "abc023"
bool(true)

string(6) "abc0x0"
bool(true)

string(6) "abc0x1"
bool(true)

string(7) "abc0x23"
bool(true)

string(6) "abc0.0"
bool(true)

string(6) "abc1.1"
bool(true)

string(8) "abc23.45"
bool(true)

string(7) "abc0e10"
bool(true)

string(7) "abc1e10"
bool(true)

string(8) "abc23e10"
bool(true)

array(0) {
}
bool(true)

array(2) {
  [0]=>
  int(0)
  [1]=>
  int(1)
}
bool(true)

object(stdClass)#1 (0) {
}
bool(true)

11 · value · object

<?

$start_index = 0;
$count = 5;
$value = new stdclass;

$return = array_fill($start_index, $count, $value);

print_r($return);
Array
(
    [0] => stdClass Object
        (
        )

    [1] => stdClass Object
        (
        )

    [2] => stdClass Object
        (
        )

    [3] => stdClass Object
        (
        )

    [4] => stdClass Object
        (
        )

)