Jump to content

[SOLVED] Which is more efficient...


spidermann

Recommended Posts

Hi guys. I'm just curious as to which of these techniques would be more efficient. They both work properly, so this is more of a question of how you guys prefer to handle this type of thing.

 

First, an if statement:

if($paged == 0 || $paged == "") { $paged = 1; }

 

Or a ternary operator:

$paged = ( get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1 );

 

The first is less code, so I'm leaning that way, but I'll ultimately go with whatever is more efficient for the server.

 

Thanks for any advice you may have.

 

Link to comment
Share on other sites

I'd do:

 

$paged = (empty($paged) || $paged == 0) ? 1 : $paged;

 

Ultimately your normal if statement would be the fastest, but that shouldn't matter because even ran through 1,000,000 times the difference in negligible (around 0.01 - 0.1 second(s)). The most important thing in cases like this is that it's easiest to read.

Link to comment
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.