Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP if() state keeps evaluating to true even though it isn't
    primarykey
    data
    text
    <p>I'm having the toughest time figuring out this problem and I can't seem to find the answer. </p> <p>Here's what I'm trying to do: I have different nav menus on my website depending on the section. I've already pre-built the different variations and on each page declare $linkbox_array, which is the array of links for my nav menu on that page. On certain pages I display horizontally and on others vertically. When vertical, I need a disclaimer to be added to the bottom of the stacked link boxes.</p> <p>So my function is trying to say this: if the $linkbox_array is $general_linkboxes and the $bodyClass is "withSidebar", then echo out a disclaimer after array item 2. Otherwise, just echo out the array items.</p> <p>So this is what I've written (forgive me if it sucks, I'm new to this):</p> <pre><code>function display_linkboxes($array) { if ($linkbox_array == $general_linkboxes &amp;&amp; $bodyClass = "withSidebar") { foreach ($array as $linkbox) { if ($linkbox == $array[2]) { echo $linkbox; global $general_disclaimer; echo $general_disclaimer; } else { echo $linkbox; } } } else { foreach ($array as $linkbox) { echo $linkbox; } } } </code></pre> <p>The problem is that it keeps spitting out the $general_disclaimer even when the two conditions aren't true. I tried to deconstruct the function and figure out where I was going wrong and I realized my if statement always evaluates to true even if I put in jibberish. For example:</p> <pre><code>function display_linkboxes($array) { if ($linkbox_array == $askjfdalfjk) { foreach ($array as $linkbox) { echo $linkbox; } } } </code></pre> <p>This evaluates to true and displays the links even though $askjfdalfjk doesn't exist. Then I have the opposite problem below. This won't display the links even though the if statement should evaluate to true:</p> <pre><code>function display_linkboxes($array) { if ($bodyClass == "withSidebar") { foreach ($array as $linkbox) { echo $linkbox; } } } </code></pre> <p>What in the world am I doing wrong?!?! Any help is greatly appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload