1

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

2
  • yes it is, sorry about that. Im mainly interested to know how to store the SORT_ASC and SORT_DESC in a variable Commented Nov 14, 2013 at 16:41
  • Sorry! It was me, I misunderstood the question =), But I guess I was surpised because you're defining a Constant, that's already a Constant - so why do you need it to be.. another Constant? Commented Nov 14, 2013 at 16:42

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you!! thats what i needed, so just so that i understand too, when i want to stare a constant value in a variable, i have to use constant()? and SORT_ASC is a constant?
Actually your second code example using $test should work. I use that all the time. I was just showing how to use the asc from the get var.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.