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
https://forums.phpfreaks.com/topic/175975-solved-which-is-more-efficient/
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.

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.