Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

How to remove repetitive values from foreach loop in php laravel

 @foreach($sections as $section)
     <div class="form-group">
         <h2>{{ $section['section_name'] }}</h2>
         <p>{{ $section['section_description'] }}</p>
         <p>{{ $section['section_intro'] }}</p>
     </div>
     <div class="form-group ms-5">
         @php
             $questions = [];
             foreach($section['question'] as $question){
                 $questions[$question['question_name']][] = $question['question_description'];
             }
         @endphp
         @foreach($questions as $question_name=>$question_descriptions)
             <h5>{{ $question_name }}</h5>
             @foreach($question_descriptions as $question_description)
                 <p class="ms-3">{{ $question_description }}</p>
             @endforeach
         @endforeach
     </div>
 @endforeach
 
PREVIOUS NEXT
Tagged: #How #remove #repetitive #values #foreach #loop #php #laravel
ADD COMMENT
Topic
Name
2+4 =