Is there any method (that doesn't use loop or recursion) to create and fill an array with values?
To be precise, I want to have an effect of
$t = array();
for($i = 0; $i < $n; $i++){
$t[] = "val";
}
But simpler.
Is there any method (that doesn't use loop or recursion) to create and fill an array with values?
To be precise, I want to have an effect of
$t = array();
for($i = 0; $i < $n; $i++){
$t[] = "val";
}
But simpler.
<?php
$keys = array('foo', 5, 10, 'bar');
$a = array_fill_keys($keys, 'banana');
print_r($a);
?>
The above example will output:
Array
(
[foo] => banana
[5] => banana
[10] => banana
[bar] => banana
)