I've got an array which gets appended regularly. I want to show the content of it like this:
$piece1 = array_slice($myarray, 1, 7);
$piece1output = implode(" ", $piece1);
echo $piece1output;
echo "<br />";
$piece2 = array_slice($myarray, 8, 7);
$piece2output = implode(" ", $piece2);
echo $piece2output;
echo "<br />";
$piece3 = array_slice($myarray, 15, 7);
$piece3output = implode(" ", $piece3);
echo $piece3output;
As you can see in every piece, I only want to show a specific area of the array.
Piece1 starts at point, piece2 at 8 and piece3 at 15. The difference between all those start points is 7.
Now I want to create a loop for this, which automatically shows the whole content of the array like in the code above.
Thank you.
Add this
for($i=1;$<=count($myarray);$i +=7){
$piece = array_slice($myarray, $i, 7);
$pieceoutput = implode(" ", $piece );
echo $pieceoutput;
echo "<br />";
}
for ($i=1; $i<=count($myarray); $i+=7){
$piece = array_slice($myarray, $i, 7);
$output = implode(" ", $piece);
echo $output."<br />";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.