我有数组
$mas = array("aaa","bbb","ccc","ddd","fff");
我想打印这个数组:
aaa bbb
ccc ddd
fff
我不知道,如何为此制作html/css,请告诉我
CSS:
span.row {
display:block;
}
span.margin {
display:inline-block;
margin-right:10px;
}
PHP:
$mas = array("aaa","bbb","ccc","ddd","fff");
echo '<span class="row">';
for($i = 0; $i < count($mas); $i++) {
echo $i % 2 == 0 ? '</span><span class="row">';
echo '<span class="margin">' . $mas[$i] . '</span>';
}
echo '</span>';
If you want to print an array with two items per line, you can try the following:
<?php
$output = "<div>";
for($i = 0; $i < count($mas); $i++)
{
if($i % 2 == 0)
$output .= "<p>".$mas[$i]." ";
else
$output .= $mas[$i]."</p>";
}
echo $output."</div>";
Use CSS to style the <p>
tags to your liking with regards to spacing.