php - 如何在 PHP 中重复一个数组?

标签 php arrays

$arr = array('1st', '1st');

上面的 $arr2 项,我想重复 $arr 以便它填充 4 项目

PHP中有单次调用吗?

最佳答案

array_fill功能应该有帮助:

array array_fill ( int $start_index, int $num, mixed $value )

Fills an array with num entries of the value of the value parameter, keys starting at the start_index parameter.

在您的情况下,代码将如下所示:

$arr = array_fill(0, 4, '1st');

关于php - 如何在 PHP 中重复一个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2963777/

相关文章:

arrays - 从两个数组的和中查找 (n*logn) 个最小元素

java - 数组:个人号码 (CPR)

javascript - 将 JSON 项目数组添加到列表框中

c# - 获取 "Index was outside the bounds of the array"异常

php - 如果条件满足则插入 mySQL 记录

javascript - 使用 header 重定向时给 div 一个样式

javascript - 长轮询或全双工连接?问题在哪里?

php - 无法将 MySQL 查询结果放入 PHP 数组

php - 使用 INNER JOIN/JOIN 进行多个查询

java - Facebook GRAPH API - 登录绕过。代币安全