This isn't really a problem, I'm just looking for the best way to do this.
I have a simple array that allows the different types of orders. What would be the best way to check and execute them? I've written a few and am wondering which would be the best to use.
$orders = array("login", "gm", "email");
//Method 1
if(isset($_GET['order']) && in_array($_GET['order'], $orders)){
$order = $_GET['order'];
} else {
$order = 'login';
}
//Method 2
$order = isset($_GET['sort']) ? in_array($_GET['sort'], $orders) ? $_GET['sort'] : "login" : "login";
//Method 3
$order = isset($_GET['sort']) ? $_GET['sort'] : "login";
$order = in_array($order, $orders) ? $order : "login";
I'll be using the same method to check for ASC and DESC.
(This is sort of a MySQL question, but more on the php side so I'm putting it here).