This is one way to do it:
<?php
if ($size = the_field('size')) {
echo "<h4>Size: $size</h4>";
}
if ($reference = the_field('reference')) {
echo "<h4>Reference: $reference</h4>";
}
?>
Another way:
<?php if ($size = the_field('size')):?>
<h4>Size: <?=$size?></h4>
<?php endif?>
<?php if ($reference = the_field('reference')):?>
<h4>Reference: <?=$reference?></h4>
<?php endif?>
or if you have short open tags enabled:
<?if ($size = the_field('size')):?>
<h4>Size: <?=$size?></h4>
<?endif?>
<?if ($reference = the_field('reference')):?>
<h4>Reference: <?=$reference?></h4>
<?endif?>
All of the above solutions consider 0 and "0" as having no value and so nothing is shown. If you need to show values of 0 you need to do this:
if (($size = (string)the_field('size'))!=="") {
echo "<h4>Size: $size</h4>";
}
if (($reference = (string)the_field('reference'))!=="") {
echo "<h4>Reference: $reference</h4>";
}
This will cast 0 to a string and become "0" which when compared to an empty string is not equal. While false and null if cast to a string become an empty string.