I have an array like this:
array(
0 => array("src" => "foo-21.gif"),
1 => array("src" => "bar-short.gif"),
2 => array("src" => "baz-1.gif"),
3 => array("src" => "whatever.gif"),
4 => array("src" => "some-long.gif"),
5 => array("src" => "xyz.gif"),
);
The value in the src
element can be anything.
However there will only be max. one element containing short
(here it is element 1) and only max. one elment containing long
(here it is element 4). They can be anywhere in the array. Or not present at all.
What I need to do now is:
- The element with
src
containingshort
must be first if present - The element conaining
long
must be last if present - The order in between does not matter.
So the example would look like this:
array(
0 => array("src" => "bar-short.gif"), // containing "short" = first
1 => array("src" => "foo-21.gif"),
2 => array("src" => "baz-1.gif"),
3 => array("src" => "whatever.gif"),
4 => array("src" => "xyz.gif"),
5 => array("src" => "some-long.gif"), // containing "long" = last
);
How would I do this? usort
does not seem like a good idea here.