How to use comma inside foreach loop?

Posted 2 months ago by laravel007

Hello

I have a list of subjects in an array. I want to print this array in blade file but I want to separate each item of the array by comma. But I don't want the comma end of the last element of the array. Let me know which one is the best approach?

Here is my code-

@foreach(explode(', ', $scholarship->selected_subjects) as $subject)
    <a href="{{ route('subjects.show', $subject) }}">
        {{ $subject }} ,
    </a>
@endforeach

Please sign in or create an account to participate in this conversation.