|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-07-24 17:42 UTC] fabien dot aurejac at gmail dot com
Description:
------------
When I try this script it should at my point of view return 0 instead of 1 ?
am I mistaken ?
Test script:
---------------
<?php
if (false && true?"1":"2") {
echo 1;
} else {
echo 0;
}
?>
Expected result:
----------------
0
Actual result:
--------------
1
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 03:00:01 2025 UTC |
The example given returns the correct result. The ternary operator is would always return a string which is always truthy. Even the integers 1 or 2 would evaluate as true; however, 0 would be false. Only the following would provide the result of 0: if (false && true ? 1 : 0) { echo 1; } else { echo 0; }