Jump to content

syntax question


dumdumsareyum

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.