Use of array_fill() function in php.
The array_fill() function is basically used for filling an array with values.
Syntax of array_fill() function: array_fill(index,number,value)
According to above syntax, there are three main Parameter of array_fill()
1- Index(This is use for indexing to the returned array)
2- Number( Number specifies the number of elements to insert)
3- Value(this is used for specifying the value to fill the array)
You can see below example the use of array_fill() function.
<?php
//here $name is a variable
$Name=array_fill(4,5,"Mac");//call array_fill()
//here $Stu_Name is a variable
$Stu_Name=array_fill(0,2,"Makran");//call array_fill()
//print $Name variable
print_r($Name);
echo "<br>";
//print $Stu_Name variable
print_r($Stu_Name);
?>
Output of above code will be as following:-
1-When you print $Name
then, result will come:
Array ( [4] => Mac [5] => Mac [6] => Mac [7] => Mac [8] => Mac )
2-When you print $Stu_Name
then, result will com
Array ( [0] => Makran [1] => Makran )
0 Comment(s)