<p>I am trying to set a flag to show or hide a page element, but it always displays even when the expression is false. </p>

<pre><code>$canMerge = ($condition1 &amp;&amp; $condition2) ? 'true' : 'false';
...
&lt;?php if ($canMerge) { ?&gt;Stuff&lt;?php } ?&gt;
</code></pre>

<p>What's up?</p>

[{'answer_id': 1764, 'author': 'Polsonby', 'author_id': 137, 'author_profile': 'https://Stackoverflow.com/users/137', 'pm_score': 1, 'selected': False, 'text': "<p>The value of 'false' is true. You need to remove the quotes:</p>\n\n<pre><code>$canMerge = ($condition1 &amp;&amp; $condition2) ? true : false;\n</code></pre>\n"}, {'answer_id': 1771, 'author': 'Rudd Zwolinski', 'author_id': 219, 'author_profile': 'https://Stackoverflow.com/users/219', 'pm_score': 6, 'selected': True, 'text': "<p>This is broken because 'false' as a string will evaluate to true as a boolean.</p>\n\n<p>However, this is an unneeded ternary expression, because the resulting values are simple true and false.  This would be equivalent:</p>\n\n<pre><code>$canMerge = ($condition1 &amp;&amp; $condition2);\n</code></pre>\n"}, {'answer_id': 12633137, 'author': 'depz123', 'author_id': 1463541, 'author_profile': 'https://Stackoverflow.com/users/1463541', 'pm_score': 0, 'selected': False, 'text': "<p>Seems to me a reasonable question especially because of the discrepancy in the way PHP works.</p>\n\n<p>For instance, the following code will output 'its false'</p>\n\n<pre><code>$a = '0';\n\nif($a)\n{\n    echo 'its true';\n}\nelse\n{\n    echo 'its false';\n}\n</code></pre>\n"}, {'answer_id': 23702630, 'author': 'Anowar Hossain', 'author_id': 3475207, 'author_profile': 'https://Stackoverflow.com/users/3475207', 'pm_score': -1, 'selected': False, 'text': '<pre><code>$canMerge = ($condition1 &amp;&amp; $condition2);\n</code></pre>\n\n<p>then</p>\n\n<pre><code>if ($canMerge){\n    echo "Stuff";\n}\n</code></pre>\n'}, {'answer_id': 73438823, 'author': 'Sohrab', 'author_id': 8805571, 'author_profile': 'https://Stackoverflow.com/users/8805571', 'pm_score': 0, 'selected': False, 'text': "<p>You are using <code>'true'</code> and <code>'false'</code> as string. Using a string(non-empty and not <code>'0'</code> and not <code>' '</code>, because these are empty strings and will be assume as false) as a condition will results the condition to be <code>true</code>.</p>\n<p>I will write some correct conditions that could be use:</p>\n<p><code>$canMerge = ($condition1 &amp;&amp; $condition2);</code></p>\n<p><code>$canMerge = ($condition1 &amp;&amp; $condition2) ? true : false;</code></p>\n<pre><code>$canMerge = ($condition1 &amp;&amp; $condition2) ? 'true' : 'false';\n...\n&lt;?php if ($canMerge == 'true') { ?&gt;Stuff&lt;?php } ?&gt;\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/1762', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/137/']