在PHP中使用无循环值填充数组 [英] Fill array with values without loop in PHP
本文介绍了在PHP中使用无循环值填充数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何方法(不使用循环或递归)来创建并用值填充数组?
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";
}
但是更简单.
推荐答案
使用 array_fill()
:
$t = array_fill(0, $n, 'val');
这篇关于在PHP中使用无循环值填充数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文