array_fill() — Fill an array with values

The array_fill() array function in PHP will create an array structured according to the parameter values you use in it. It takes three parameters. The first parameter is the index number that you want your array to start with. The second parameter is how many elements you wish the array to have. The third parameter is the filler value that all of the array elements will have.


   array_fill_keys(array, value);


$array = array("index1","index2","index3");
$newVals = "newvalue";
$newArray = array_fill_keys($array, $newVals);

foreach ($newArray as $key => $value) {
        echo "$key - <strong>$value</strong> <br />"; 


index1 - newvalue
index2 - newvalue
index3 - newvalue

Similar Example: