blasto333 Posted February 2, 2011 Share Posted February 2, 2011 echo 'a'.false ? 'b' : 'c'; Why does this echo b? Thank you, Chris Quote Link to comment https://forums.phpfreaks.com/topic/226463-string-concatination/ Share on other sites More sharing options...
BlueSkyIS Posted February 2, 2011 Share Posted February 2, 2011 'a' is true. concatenating false to the string doesn't change that. what are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/226463-string-concatination/#findComment-1168884 Share on other sites More sharing options...
ManiacDan Posted February 2, 2011 Share Posted February 2, 2011 This is what PHP is doing: echo 'a'.false ? 'b' : 'c'; //becomes echo strval('a'.false) ? 'b' : 'c'; //becomes if ( strval('a' . false) == true ) { echo 'b'; } else { echo 'c'; } -Dan Quote Link to comment https://forums.phpfreaks.com/topic/226463-string-concatination/#findComment-1168889 Share on other sites More sharing options...
jamesxg1 Posted February 2, 2011 Share Posted February 2, 2011 A simple way to understand this is; echo $isTrue ? 'YES' : 'NO'; This is relatively the same as; if($isTrue) { echo 'YES'; } else { echo 'NO'; } James. Quote Link to comment https://forums.phpfreaks.com/topic/226463-string-concatination/#findComment-1168898 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.