Page 1 of 1

Short hand question

Posted: Wed Mar 26, 2003 10:48 am
by EricS
I found the following code inside some classes I've been looking at and I'm not sure exactly what it means.

Code: Select all

($type == true)
    ? mysql_pconnect($host, $user, $pass)
    : mysql_connect($host, $user, $pass)
My guess is this is some kind of shorthand for an if statement. If type is true connect using persistent connections else connect without persistent connections. Is that how it works?

Thanks for everything.

Posted: Wed Mar 26, 2003 11:19 am
by twigletmac
It's called the ternary operator and is basically (as you worked out) a short-hand for simple if statements, there's a bit of info about it in here:
http://www.php.net/manual/en/language.o ... arison.php

Mac

Thanks

Posted: Wed Mar 26, 2003 11:42 am
by EricS
Thanks twigletmac.... wonderful help as always. :D