Of the following, which conditional statement is best practice:
if ($_GET['type'] == 'user' || $_GET['type'] == 'salesmen')
or
if ($_GET['type'] == ('user' || 'salesmen'))
Thanks for your help.
Always use the first one:
if ($_GET['type'] == 'user' || $_GET['type'] == 'salesmen')
The second one is a valid PHP ststement but it will produce unexpected results ( Not the output you are expecting ).
Have you tried it? One simple try would point you that the second part will not work as you expected.
However, I would suggest in_array()
if (in_array($_GET['type'], array('user', 'salesmen'))) {
//
}
or
$type = array('user', 'salesmen');
if (in_array($_GET['type'], $type)) {
//
}
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