limitphp Posted January 8, 2009 Share Posted January 8, 2009 I think this is an if/else statement: <?php $currentpage = is_numeric($_GET['currentpage']) ? (int) $_GET['currentpage'] : 1; Can someone help break it down so I can understand how the if/else statement is constructed? Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/140036-solved-help-with-interpreting-alternate-syntax-for-ifelse-statement/ Share on other sites More sharing options...
448191 Posted January 8, 2009 Share Posted January 8, 2009 If the value is a numeric string, cast it to an integer. Otherwise use 1. Assign the result to $currentpage. Quote Link to comment https://forums.phpfreaks.com/topic/140036-solved-help-with-interpreting-alternate-syntax-for-ifelse-statement/#findComment-732649 Share on other sites More sharing options...
.josh Posted January 8, 2009 Share Posted January 8, 2009 It's a ternary operator. (condition)? true : false Same as saying if(is_numeric($_GET['currentpage'])) { $currentpage = (int) $_GET['currentpage']; } else { $currentpage = 1; } Quote Link to comment https://forums.phpfreaks.com/topic/140036-solved-help-with-interpreting-alternate-syntax-for-ifelse-statement/#findComment-732650 Share on other sites More sharing options...
limitphp Posted January 8, 2009 Author Share Posted January 8, 2009 thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/140036-solved-help-with-interpreting-alternate-syntax-for-ifelse-statement/#findComment-732651 Share on other sites More sharing options...
limitphp Posted January 8, 2009 Author Share Posted January 8, 2009 can you have only two parts: condition ? if true and not have the : if not true; Quote Link to comment https://forums.phpfreaks.com/topic/140036-solved-help-with-interpreting-alternate-syntax-for-ifelse-statement/#findComment-732660 Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 can you have only two parts: condition ? if true and not have the : if not true; You can try, not sure if that is kosher, but give it a try, you can't really hurt anything by trying. Edit: Nope you cannot, syntax error. Quote Link to comment https://forums.phpfreaks.com/topic/140036-solved-help-with-interpreting-alternate-syntax-for-ifelse-statement/#findComment-732661 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.