Is there anyway to order an array in this way? For example if I had this array:
$array = array("foo", "bar", "item", "item", "foo", "foo");
And I wanted to order it so that it was “foo”, “foo”, “foo”, “item”, “item”, “bar” is there any way to do that?
Would this do?
will give you
or do you necessarily need them as repeated values? if yes, you may go for something like:
This is ugly code, but demonstrates the technique. It is also easy to make it good-looking with php 5.3 closures, but I don’t know if you’re on 5.3. That would look like this: