Easiest way is to do this:
Code:
<table>
<tr>
<th>Reference</th>
</tr>
<?php
session_start();
$references = explode(',' $_SESSION['portfolio']);
foreach($references as $ref) {
if (strlen($ref) > 0) {
?>
<tr>
<td><?= $ref; ?></td>
</tr>
<?php
}
}
?>
</table>
Basically that's now checking the length of the $ref before printing the row, so it'll automatically cut the first empty one out.