I want to use array_multisort() to sort a bunch of arrays I have. Depending on what order you pass the arrays, it changes how it sorts, IE array_multisort($name, $ID) will sort by name first, and ID second. I'd like to do something like:
$order = '$name, $ID';
array_multisort($order);
But you can't do that, because it tries to sort $order, which is not an array. How can I make it parse $order first?why not leave it like it was? you can't parse $order before it gets to the array, cause $order will be what ever $name and $ID is. not sure if you can stick 2 array in to one variable without doing some splicing.Nope...$order actually holds the string '$name, $ID' because of the single quotes.
The reason I was trying this was to make it so I could pass $order to it, and change how it is ordered without having to have a big switch statement for all the different cases.aren't these array's?
'$name, $ID'
cause that is what you need to do the multisort.yes...they are arrays. I just thought that since they get sent to array_multisort like this: array_multisort($name, $ID) that I could store the string $name, $ID in $order, and pass the CONTENTS of $order to array_multisort, but it sends the variable instead of the CONTENTS of the variable.
I figured that if I could do that, then I could send $order to the file as $ID, $name instead if I wanted.ahh no you can't do it that way.
try this
$order = '$$name, $$ID';
array_multisort($order);
that should keep the associationI echo $order, and I get:
$$ID, $$name
Then I get this error:
Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in /usr/home/sites/www.autotransportteam.com/web/employees/dispatch/view_assigned.php on line 164
And of course, line 164 is:
array_multisort("$order");you don't need th esingle quopte in teh array functino. try hti sone
$order = $$name.','.$$ID;
array_multisort($order);
forgot that in single quotes the variables are not parsed.
$order = '$name, $ID';
array_multisort($order);
But you can't do that, because it tries to sort $order, which is not an array. How can I make it parse $order first?why not leave it like it was? you can't parse $order before it gets to the array, cause $order will be what ever $name and $ID is. not sure if you can stick 2 array in to one variable without doing some splicing.Nope...$order actually holds the string '$name, $ID' because of the single quotes.
The reason I was trying this was to make it so I could pass $order to it, and change how it is ordered without having to have a big switch statement for all the different cases.aren't these array's?
'$name, $ID'
cause that is what you need to do the multisort.yes...they are arrays. I just thought that since they get sent to array_multisort like this: array_multisort($name, $ID) that I could store the string $name, $ID in $order, and pass the CONTENTS of $order to array_multisort, but it sends the variable instead of the CONTENTS of the variable.
I figured that if I could do that, then I could send $order to the file as $ID, $name instead if I wanted.ahh no you can't do it that way.
try this
$order = '$$name, $$ID';
array_multisort($order);
that should keep the associationI echo $order, and I get:
$$ID, $$name
Then I get this error:
Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in /usr/home/sites/www.autotransportteam.com/web/employees/dispatch/view_assigned.php on line 164
And of course, line 164 is:
array_multisort("$order");you don't need th esingle quopte in teh array functino. try hti sone
$order = $$name.','.$$ID;
array_multisort($order);
forgot that in single quotes the variables are not parsed.