PHP Function Array_Fill
The php function array_fill is an inbuilt-function that is used to fill an array with a given pre-filled value. It accepts three parameters – start index, number of elements, and value. The function returns a filled user-defined array as output with values described by the parameter value.
The first parameter, start_index, is the starting index of the return array. This can be negative, in which case it will begin at index 0. The second parameter is the number of elements to insert into the return array. This must be greater than or equal to zero, and will throw an E_WARNING if it is less than zero. The third parameter is the value to use to fill the array, and can be any type.
Using this built-in PHP function can be extremely helpful in creating indexed arrays of a specific shape, and setting default values for them. This is useful in a variety of scenarios, including initializing arrays and preparing data for processing.
Technical Details of php Function array_fill
The array_fill() function creates an indexed array of the specified shape, and sets all of its cells to a given value. It takes three inputs — start index, number of elements, and value — to create a user-defined array as an output. The first index of the returned array will be start_index, and all subsequent indices will begin at the second element. If start_index is negative, the array will begin at index 0, and all subsequent indices will be numbered from there.