0

我有数组

 $mas = array("aaa","bbb","ccc","ddd","fff");

我想打印这个数组:

 aaa bbb
 ccc ddd
 fff

我不知道,如何为此制作html/css,请告诉我

4

2 回答 2

1

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>';
于 2012-08-02T15:21:09.093 回答
1

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.

于 2012-08-02T15:21:53.847 回答