我假设单词在数组或嵌套数组中。我有这个建议:
<?php
$words = array("wordb 1", "wordb 2", "wordk 1", "wordk 2", "wordb 3", "wordk 3", "wordk 4", "wordk 5");
$wordsb = '';
$wordsk = '';
foreach($words as $word) {
if(strpos($word,'b')!== false) {
$wordsb[] = $word;
}
if(strpos($word,'k')!== false) {
$wordsk[] = $word;
}
}
$length = (count($wordsb) > count($wordsk)) ? count($wordsb) : count($wordsk);
?>
<table border="1" cellpadding="5">
<thead>
<tr>
<th>Words With b On Left</th>
<th>Words With k On Right</th>
</tr>
</thead>
<tbody>
<?php for($i = 0; $i < $length; $i++) { ?>
<tr>
<td><?php echo (isset($wordsb[$i]) && !empty($wordsb[$i])) ? $wordsb[$i] : " " ; ?></td>
<td><?php echo (isset($wordsk[$i]) && !empty($wordsk[$i])) ? $wordsk[$i] : " " ; ?></td>
</tr>
<?php } ?>
</tbody>
</table>