Domanda

Hi im interested to let my query tell my web app how to sort an array.

Everything is working fine, but i can't figure out a clever way to have the URL (page.php?order=asc) grab that query with:

$order = $_GET['order'];

and put it into:

array_multisort($sort['name'], SORT_ASC, $array);

this doesnt seem to work:

$test = SORT_ASC;
array_multisort($sort['name'], $test, $array);

Had a hard time googling for this, so hopefully some smart brain here can help me out :) thank you

È stato utile?

Soluzione

Your second code example using $test should work, I use that all the time. Here is how to use the asc from $_GET['order']:

$order = constant('SORT_' . strtoupper($_GET['order']));
array_multisort($sort['name'], $order, $array);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top