title: Advanced PHP foreach() loop..(nested if/else)
body: <p>I'm having a bit of a brain-fart here...lol</p>
  
  <p>I was using a forloop() initially for this.. but then the conditions got a bit more advanced on things I needed to check for, as well as the output based on found/not found..</p>
  
  <p>My problem is ensuring that on consecutive loops.. the 'else' on the (no access) potion only gets echo'd once...  but of course on every 'loop' it will check from the top and if not a match output the 'no-access' text.. (on every iteration).. where it should only output once.</p>
  
  <p>Originally there was only a few  if() statement/checks in the foreach() loop.. where a simple break; took care of things fine...</p>
  
  <p>but these if()'s turned into if/else.. which means the else will get 'triggered' on the next 'loop'..  how can this be prevented?</p>
  
  <pre><code>$arrwebinars = ("Name1", "Name3");
  
  foreach($arrwebinars as $webinar) {
  
     /* Webinar 1 */
     if($webinar == 'Name1') {    
          if($web01_title != '') {
              echo "available";                   
          } else {
              echo "not available";
          }
    } else {
      echo "no access";
    } 
  
    /* Webinar 2 */
    if ($webinar == 'Name2') {    
       if ($web02_title != '') {
          echo "available";                   
       } else {
          echo "not available";
       }
    } else {
       echo "no access";
    }
  
    /* Webinar 3 */
    if ($webinar == 'Name3') {    
      if($web03_title != '') {
          echo "available";                   
      } else {
          echo "not available";
      }
    } else {
      echo "no access";
    }
  }
  </code></pre>
  
  <p>is there some other sort of 'control' I can use to ensure the main if/else only gets executed once?   </p>
  
  <p>Sorry , I am having a hard time trying to describe this one, hopefully the code explains it all (and the problem)</p>
  
  <p>thanks.</p>
  
  <hr>
  
  <p>update:
  Current State:  reverted back to foreach() loop.</p>
  
  <p>User is only authorized for 2 vids (#5 &amp; #6 we'll say..can be any of the 6 in reality)</p>
  
  <p>Upon first loop/iteration.. vids 1-4 output (no access for you!) (because they dont, only #5 &amp; #6 as stated above)</p>
  
  <p>no. 5 outputs the embed code fine (access)</p>
  
  <p>no. 6 says 'No access for you'.. (even though they do/should have access)</p>
  
  <p>Upon the scond iteration..vids 1-4 are duplicated, and again say "No access for you" (outside of it being a duplication..this is correct).. however, vid #5 NOW says "no access for you" (first loop it outputted fine, second loop it is looking for a new 'match' while not what I want.. in theory this is correct.. but should have a duplicate)</p>
  
  <p>Vid #6 is NOW outputting the embed code (where as on first loop it did not)..</p>
  
  <p>The user has only purchased access to 2 vids.. so the loop only happens twice.</p>
  
  <p>but I get '12' echo's</p>
  
  <p>No matter what I should only get 6 echo's  with 1 out put per video  (available/not available -or- no access)</p>
  
  <p>I cant seem to wrap my head around this today.. :(</p>
  
  <p>Goal I want achieve:</p>
  
  <p>6 outputs TOTAL</p>
  
  <p>each output (echo) should ONLY have:
  available or not available printed (this is the nested conditional check for the blank title)
  -or-
  no access</p>
  
  <p>there are 6 video to check against.
  the user can have purchased access to 1 or up to all 6 vids </p>
  
  <p>first check is: is the webinar name in their purchased array found in the total available 6 vids available</p>
  
  <p>second tier conditional check:
  if YES (match found == access)...then check to see if the title is missing (if there output access [video embed code]... if not there output text 'not available yet')</p>
  
  <p>(going back to first conditional check) if there is NO ACCESS (match not found).. output 'no access' text.</p>
  
  <p>This works if I wanted duplicates on the stage/page.. (but I dont!)  LOL..</p>
  
  <p>I need to be limited to ONLY 6 outputs,.. as there are only a total of 6 vids available.</p>
  
  <p>I DO NOT WANT:</p>
  
  <p>on loop 1 it outputs access for vid#1 and #2-#6 are no access..
  on loop 2 it re-states all of these outputs, has vid#1 no-access now, vid#2 has access and vids #3-#6 are no access...</p>
  
  <p>etc.etc..  and the cycle continues.    I'm getting lost on this one!..</p>
  
  <p>thanks!</p>