beefsupreme
beefsupreme

Reputation: 123

How to create an if statement in PHP based on HTML values

I'm quite new to php, so be gentle.....

I have a basic list view that I have set up to match my html/css styles on a sidebar.....but every few listgroup items there are 'header' items on the list that do not inherit the same styles as other listgroup items.

For example, one list group item would have checkboxes and save icons where as the heading list group item would be the same size but would have bold text and no buttons.

This is what I have. On the section below the main one, I have the HTML values for a header list group item. Is it possible to tell the PHP to detect 'step-heading' as a class and then display the following code for all relevant values?

EDIT: I know that in the if-statement that $step-heading is invalid because I have not declared it as a variable...I simply have no idea what to put there otherwise.

            <?php foreach ($tasks as $i => $task) { ?>

                <li class="list-group-item" tabindex="-1">
                    <a class="listgroupwrap" href="#g<?= $i + 1 ?>">
                    </a>
                <span class="step-number-container"> <?=$i + 1 ?>
                </span>
                    <span class="btn-check">
                        <i class="glyphicon glyphicon-ok"></i>
                    </span>
                    <!--<span class="step-checkbox"></span>-->

                        <span class="step-name"><?php echo $task["name"] ?>
                            </span>
                                <span class="step-show-hide">

                                        <span class="btn">
                                            <i class="glyphicon glyphicon-chevron-right">
                                            </i>
                                        </span>
                                </span>
                </li>

            <?php } ?>


<?php
            if ( $tasks == "step-heading" ) {
            ?>
                <li class="list-group-item step-heading" tabindex="-1">
                    <span class="step-number-container">2</span>
                    <a class="listgroupwrap" href="#g<?= $i + 1 ?>">
                    </a>
                    <span class="step-name">Pre-meeting email, send below items:</span>

                </li>
                <?php;
            }
            ?>

Upvotes: 0

Views: 77

Answers (1)

Marc B
Marc B

Reputation: 360572

You can't have it both ways:

        <?php foreach ($tasks as $i => $task) { ?>
                       ^^^^^^---array

        if ( $tasks == "step-heading" ) {
             ^^^^^^---array-as-string

An array in string context is simply the literal word Array.

Perhaps you mean:

        if ( $task == "step-heading" ) {
                  ^---no S

instead.

Upvotes: 1

Related Questions