Actually, you need to surround the UL with the check. Otherwise, you will get an empty tag "ul", which is not needed:
<?php if (!empty($person['CastsMovie'])) { ?>
<ul>
<?php foreach($person['CastsMovie'] as $cast) { ?>
<li><?php echo $this->Html->link($cast['Movie']['name'], array('controller' => 'movies', 'action' => 'view', $cast['movie_id'], 'admin' => true), array('escape' => false)); ?> (<?php echo date("Y", strtotime($cast['Movie']['MovieDetail']['release_date'])); ?>)</li>
<?php } ?>
</ul>
<?php } ?>
this means: you check if there are any elements of the list (in your case CastsMovies for this person), and if so, you display the list (ul + li). if not a complete list will be omitted (and not just li children).
source
share