I have 4 data points that can exist for a particular item. Existing is defined as having a value of "Y." Here are the 4 things:
INST_UNIV
INST_4YEAR
INST_2YEAR
INST_VOTECH
What I'd like to do is loop through them and if each has a value of "Y," display the associated blurb of text. Finally, if the number is greater than 1, I'd like them comma separated with "or" before the last item. Here's the mess of code I've been playing with. It works, but because the array is hardcoded, even if one of the variables returns an empty value, the comma still displays. Any help is appreciated.
<li>
Must attend:
@php
$univ = ( $instance->applicationCharacteristics->first()->INST_UNIV == 'Y')? "a university" : "";
$fourYear = ( $instance->applicationCharacteristics->first()->INST_4YEAR == 'Y')? "a four-year college" : "";
$twoYear = ( $instance->applicationCharacteristics->first()->INST_2YEAR == 'Y')? " two-year college" : "";
$voTech = ( $instance->applicationCharacteristics->first()->INST_VOTECH == 'Y')? "a vocational-tech school" : "";
$items = array("$univ", "$fourYear", "$twoYear", "$voTech");
$items[count($items) - 1] = "or " . $items[count($items) - 1];
$items_string = implode(", ", $items );
echo $items_string;
@endphp
</li>