如果我们有一个字符串并且知道数组计数,是否有任何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'];
答案 0 :(得分:0)
是的,有一个预定义的数组函数,即array_fill_keys
,用于填充给定的数组键。以下是array_fill_keys
的示例以及您问题的答案。
$count = 3;
$a = array_fill_keys(range(0,$count - 1), '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
)