Fill array with values without loop in PHP
use array_fill()
:
$t = array_fill(0, $n, 'val');
I think you can use
$array = array_pad(array(), $n, "val");
to get the desired effect.
See array_pad() on php.net
$a = array('key1'=>'some value', 'KEY_20'=>0,'anotherKey'=>0xC0DEBABE);
/* we need to nullify whole array with keep safe keys*/
$a = array_fill_keys(array_keys($a),NULL);
var_export($a);
/*result:
array(
'key1'=>NULL,
'KEY_20'=>NULL,
'anotherKey'=>NULL
);
*/