1 回答
TA贡献1831条经验 获得超10个赞
一种解决方案:
您可以像这样修改代码:
<?php
$my_array = array("Tesla", "BMW", "Ford", "Jeep");
$totalCount = count($my_array); // get the total count of your array
$iteration = $totalCount*5; // multiply as per your iteration
$newArray = array(); // initialize an array
$incArr = 0; // increment for your value's array
for ($i=1; $i <= $iteration; $i++) {
if(($i % 5 == 0) ) { // at every fifth index
$newArray[] = $my_array[$incArr]; // store actual value
$incArr++;
}
else{
$newArray[] = "..."; // store if not a 5th value
}
}
?>
结果:
<?php
$number = 1;
foreach ($newArray as $key => $value) {
echo $number.") ".$value."<br/>";
$number++;
}
?>
沙盒:
应打印为:
1) ...
2) ...
3) ...
4) ...
5) Tesla
6) ...
7) ...
8) ...
9) ...
10) BMW
11) ...
12) ...
13) ...
14) ...
15) Ford
16) ...
17) ...
18) ...
19) ...
20) Jeep
- 1 回答
- 0 关注
- 120 浏览
添加回答
举报