如果我们有字符串和数组长度,是否有PHP函数来生成数组?
如果我们有一个字符串并且知道数组计数,有没有PHP函数来生成数组 例如:如果我们有字符串和数组长度,是否有PHP函数来生成数组?,php,arrays,Php,Arrays,如果我们有一个字符串并且知道数组计数,有没有PHP函数来生成数组 例如: $sample = 'required|numeric|between:0,99.99'; $count = 3; $validation_arr = ['required|numeric|between:0,99.99','required|numeric|between:0,99.99','required|numeric|between:0,99.99']; 是的,有一个预定义的数组函数,即array\u fi
$sample = 'required|numeric|between:0,99.99';
$count = 3;
$validation_arr = ['required|numeric|between:0,99.99','required|numeric|between:0,99.99','required|numeric|between:0,99.99'];
是的,有一个预定义的数组函数,即
array\u fill
,用于填充给定的数组键。下面是数组填充的示例以及对您问题的回答
$count = 3;
$a = array_fill(0,$count, 'required|numeric|between:0,99.99');
print_r($a);
//Output Array
(
[0] => required|numeric|between:0,99.99
[1] => required|numeric|between:0,99.99
[2] => required|numeric|between:0,99.99
)
$validation\u arr=array\u fill(0,$count,$sample)
工作起来很有魅力。谢谢