Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

PHP else if not working.

PHP Problem. I have a piece of script that wont work. The PHP is to add a class and it won't go past the 3rd iteration.
here:
         <?php elseif ($valuesNum == 3) : ?>solution-skills
              <?php else : ?>expand
If I add a fourth box, it gives it the class solution-skills and not expand.  I do not have a url for you to look at.  Is this something simple I am missing?

<div class="flipper effect__hover box box-solution box-solution-simple ripplelink" ontouchstart="this.classList.toggle('hover');">
      <div class="flipper__front box-<?php if ($valuesNum == 1) : ?>solution-messages
          <?php elseif ($valuesNum == 2) : ?>solution-content
          <?php elseif ($valuesNum == 3) : ?>solution-skills
          <?php else: ?>expand
          <?php endif; ?>">
        <span class="flipper__text">
                <span class="textline"><a href="<?php the_sub_field('value_link_url'); ?>"><?php the_sub_field('value_headline'); ?></a>&nbsp;</span>
                <span class="icon icon-arrow-right-knockout"></span>
            </h2>
        </span>
      </div>
      <div class="flipper__back box-<?php if ($valuesNum == 1) : ?>solution-messages
          <?php elseif ($valuesNum == 2) : ?>solution-content
              <?php elseif ($valuesNum == 3) : ?>solution-skills
              <?php else : ?>expand
                  <?php endif; ?>">
        <span class="flipper__text">
            <p><?php the_sub_field('value_content'); ?></p>
        </span>
      </div>
    </div>
<?php endwhile; ?>

Open in new window

SOLUTION
Avatar of NerdsOfTech
NerdsOfTech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree with Chris and like his approach even better; to boot, not only does his code reduce the redundancy of the previously written control statements, he showcases the alternative : syntax of switch() in a clean, readable way.
For optimal readability and flexibility, use switch() when there are more than three conditions tested.