1 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超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
}
}
?>
結(jié)果:
<?php
$number = 1;
foreach ($newArray as $key => $value) {
echo $number.") ".$value."<br/>";
$number++;
}
?>
沙盒:
應(yīng)打印為:
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 關(guān)注
- 154 瀏覽
添加回答
舉報(bào)