Manixat Posted January 12, 2013 Share Posted January 12, 2013 Hello.. I have this shorthand if <div id='holder' style='overflow:<?php echo (isset($ad) and $write==0 ? "auto" : "hidden"); ?>;' > which no matter the conditions, always returns 1? <div id="holder" style="overflow:1;"> What is up with that? Link to comment https://forums.phpfreaks.com/topic/273071-shorthand-if-returns-1/ Share on other sites More sharing options...
kicken Posted January 12, 2013 Share Posted January 12, 2013 Use && for a logical-and, not 'and'. 'and' has low precedence so it is evaluated last. In other words, your code runs as if it were written like: $tmp = $write==0 ? "auto" : "hidden"; $tmp = isset($ad) and $tmp; echo $tmp; Link to comment https://forums.phpfreaks.com/topic/273071-shorthand-if-returns-1/#findComment-1405191 Share on other sites More sharing options...
Barand Posted January 12, 2013 Share Posted January 12, 2013 nm Link to comment https://forums.phpfreaks.com/topic/273071-shorthand-if-returns-1/#findComment-1405192 Share on other sites More sharing options...
Manixat Posted January 12, 2013 Author Share Posted January 12, 2013 Well I've been using "AND" all the time and never experienced any issues, however this was the case here, I guess I have just been lucky. Thanks! Link to comment https://forums.phpfreaks.com/topic/273071-shorthand-if-returns-1/#findComment-1405193 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.