dumdumsareyum Posted March 30, 2008 Share Posted March 30, 2008 What does it all mean? ??? I'm trying to let my search results be displayed on multiple pages. I have edited a program in the past that had this functionality so I'm using it as a guide, but I'm not sure how this line of code works: $prev_page = ($thispage-1 <= 0) ? 0 : $thispage-1; Would anyone mind explaining this syntax (I don't get what the ? and : are doing, I mean I get that it's trying to say that the previous page is equal to this page -1, unless it's less than or equal to zero, just not quite sure exactly how it's saying that....)? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/98643-syntax-question/ Share on other sites More sharing options...
redarrow Posted March 30, 2008 Share Posted March 30, 2008 if ? <<<< : <<<< else http://www.totallyphp.co.uk/tutorials/using_if_else_ternary_operators.htm ternary operater Link to comment https://forums.phpfreaks.com/topic/98643-syntax-question/#findComment-504812 Share on other sites More sharing options...
MadTechie Posted March 30, 2008 Share Posted March 30, 2008 $prev_page = ($thispage-1 <= 0) ? 0 : $thispage-1; is basically a short if statment its short for if($thispage-1 <= 0) { $prev_page=0; }else{ $prev_page=$thispage-1; } Link to comment https://forums.phpfreaks.com/topic/98643-syntax-question/#findComment-504814 Share on other sites More sharing options...
ucffool Posted March 30, 2008 Share Posted March 30, 2008 It's called a ternary conditional. expression ? ValueIfTRUE : ValueIfFALSE; Evaluate expression, if it is true, the value after the ? and before the : is used. If it is false, the value after the : and before the ; is used. It returns either the values defined (in your case, assigning them to $prev_page). Link to comment https://forums.phpfreaks.com/topic/98643-syntax-question/#findComment-504816 Share on other sites More sharing options...
dumdumsareyum Posted March 30, 2008 Author Share Posted March 30, 2008 Awesome. That helps a lot I was getting nowhere searching the php manual for "?" and ":" hehe. Link to comment https://forums.phpfreaks.com/topic/98643-syntax-question/#findComment-504822 Share on other sites More sharing options...
MadTechie Posted March 30, 2008 Share Posted March 30, 2008 It's called a ternary conditional. its "Ternary Operator" or "Conditional Operator" Link to comment https://forums.phpfreaks.com/topic/98643-syntax-question/#findComment-504851 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.