if data is static and you are positive that this is the code that you wish to implement, then your logic needs to change from less than two to a more precise identifier. A switch will work better for you and allow you to adjust the code if you add more items to the array (which should not contain curly braces, rather square brackets).
<?php
$data=["egg","york","pork"];
$total = count($data);
for ($i = 0; $i < $total; $i++) {
switch ($i) {
case 0: echo '<p>SECTION A<br>'; break;
case 2: echo '</p>SECTION B<br>'; break;
} echo $data[$i] . '<br>';
}
$data2 = (array) ['Section A' => (array) ["egg","york"], 'Section B' => (array) ["pork"]];
foreach ($data2 as $section => $array) {
echo '<p>' . $section . '<br>';
foreach ($array as $type) {
echo $type.'<br>';
} echo '</p>';
}
?>
but i recommend that you build your arrays to structure and identify data, then looping will be easy and the resulting code will be cleaner and more logical. vide data2 array and the subsequent code above.