title: Multi loops in PHP language
body: <p>I have three loops of values which confuse me how to show the correct output. </p>
  
  <p>First I have a sentence for instance this:</p>
  
  <blockquote>
    <p>Back in 1951 , the astronomer , Gerard P . Kuiper , was pondering the
    crowns , especially those that loop around the Sun in less than 200
    years . These comets include Halley's Comet - last seen from earth in
    1985/86 - and Shoemaker-Levy which crashed into Jupiter in 1994 . He
    worked out that comets like these would have to come from a belt
    fairly close to the planets of the solar system . He noticed that
    these comments also tend to come hurting in from outer space quite
    close to the plane of the planets , rather than from just any old
    direction . Kuiper predicted that there should be a flattened belt or
    frisk of comets and asteroids , beginning just outside the orbit of
    Neptune 30 AU and reaching out to about 1,000 AU or astronomical units
    . But finding a comet past Neptune , is like trying to see a 100-watt
    light bulb at 20 times the distance of the Moon . Well , back in 1992
    , our television technology finally got good enough .</p>
  </blockquote>
  
  <p>Now I marked some of the keywords in my database table as following :</p>
  
  <pre><code>crowns,that,comments,frisk,finding
  </code></pre>
  
  <p>And I will have some answers from the user side :</p>
  
  <pre><code>was,that,comments,see,finding
  </code></pre>
  
  <p>Now I need to show if the user marked the correct values inside the text, so first I tried to use a foreach loop and in array function, but the problem is with the duplicated keywords such as <em>that</em>. </p>
  
  <p><strong>How can I fix the problem of showing user answers and check if his/her answer is correct compared to the marked keywords.</strong> </p>
  
  <pre><code>$text_array =  preg_split("/(\w\S+\w)|(\w+)|(\s*\.{3}\s*)|(\s*[^\w\s]\s*)|\s+/", $object-&gt;text,-1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE) ;
  $answvals=[]; $answvals = explode(',',  $object-&gt;answer-&gt;answer);
  $marked_keys = explode(',', $object-&gt;marked_keys);
  
  
          &lt;p class="card-text"&gt;
  
              @foreach($text_array as $val)
  
              &lt;span class="
               @if( $object-&gt;answer != null )
                        @if(in_array($val,$answvals))
                             @if(in_array($val,$marked_keys))
                      bg-success
                           @else
                         bg-danger
                           @endif
                    @endif
  
              @endif
              "&gt;
              {{str_replace(' ', '', $val)}} &lt;/span&gt;
          @endforeach
          &lt;/p&gt;
  </code></pre>