I have long IF:
if(rand(1, 100) == 22 && $smth < time() &&
$smths > 5 && $sxsxsx > 250 &&
!$_SESSION['false'])
{
echo "wow, big if just happened!";
}
How to write it more "prettier"?
I prefer breaking before the boolean operators.
if(rand(1, 100) == 22
&& $smth < time()
&& $smths > 5
&& $sxsxsx > 250
&& !$_SESSION['false']
)
I like to name my conditions and group them so its clear what their purpose is.
$is22 = rand(1, 100) == 22;
$someTime = $smth < time() && $smths > 5;
$meetsSx = $sxsxsx > 250;
$inSession = !$_SESSION['false'];
if ($is22 && $someTime && $meetsSx && $inSession) {
// do something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With