2017
03.24

PHP If statement – micro-optimization

I have tested a difference between these if statements:

$myVar = 'newVal';
if ($i % 2)
{
$myVar = 'oldVal';
}

if ($i % 2)
{
$myVar = 'oldVal';
}
else
{
$myVar = 'newVal';
}

$myVar = ($i % 2) ? 'oldVal' : 'newVal';

Winner: 2nd code.
Looser: 3rd one.

Test can be seen here

ENVATO FLASH STOCK ENVATO THEME FOREST

CBDB.cz - moje knihy