Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.