Change language

PHP array_fill () function

Syntax:
array_fill ($start_index, $number_elements, $values)
Parameter:
The array_fill() function takes three parameters and is described below:
  • $start_index:This parameter specifies the starting position of filling the values ​​in the array that the user wants to create. If $start_index is negative, the first index of the returned array will be $start_index, and subsequent indices will start at zero. So it’s better to give it a positive value. This parameter is required and must be specified.
  • $number_elements:This parameter refers to the number of elements that the user wants to enter into the array. $Number_elements must be positive (including 0, for version 5.6.0), otherwise E_WARNING is thrown. This is also a required parameter.
  • $values:this parameter refers to the values ​​that we want to insert into the array. These values ​​can be of any type.
  • Return type : array_fill() returns a filled custom array, the values ​​of which are described by the $value parameter .Examples:
    Input: $start_index = 2; $number_elements = 3; $values ​​= "Geeks"; Output: Array ([2] = > Geeks [3] = > Geeks [4] = > Geeks) Input: $start_index = -10; $number_elements = 3; $values ​​= 45; Output: Array ([-10] = > 45 [0] = > 45 [1] = > 45)
    The following program illustrates how the array_fill() function in PHP works:  
    // PHP code to illustrate how array_fill() works function Fill ( $start_index , $number_elements , $values ​​ ) { return ( array_fill ( $start_index , $number_elements , $values ​​ )); }  
    // Driver code $start_index = 2; $number_elements = 5; $values ​​ = "Geeks" ; print_r (Fill ( $start_index , $number_elements , $values ​​ )); ?>
    Output:
    Array ([ 2] = > Geeks [3] = > Geeks [4] = > Geeks [5] = > Geeks [6] = > Geeks)
    Link: http://php.net/manual/en/function.array-fill.php

    Shop

    Learn programming in R: courses

    $

    Best Python online courses for 2022

    $

    Best laptop for Fortnite

    $

    Best laptop for Excel

    $

    Best laptop for Solidworks

    $

    Best laptop for Roblox

    $

    Best computer for crypto mining

    $

    Best laptop for Sims 4

    $

    Latest questions

    NUMPYNUMPY

    psycopg2: insert multiple rows with one query

    12 answers

    NUMPYNUMPY

    How to convert Nonetype to int or string?

    12 answers

    NUMPYNUMPY

    How to specify multiple return types using type-hints

    12 answers

    NUMPYNUMPY

    Javascript Error: IPython is not defined in JupyterLab

    12 answers


    Wiki

    Python OpenCV | cv2.putText () method

    numpy.arctan2 () in Python

    Python | os.path.realpath () method

    Python OpenCV | cv2.circle () method

    Python OpenCV cv2.cvtColor () method

    Python - Move item to the end of the list

    time.perf_counter () function in Python

    Check if one list is a subset of another in Python

    Python os.path.join () method