I have an array in PHP containing word "Paying" and years like this:
Array
(
[0] => 2014
[1] => 'Paying'
[2] => 2013
[3] => 2015
)
I want to short it so the "Paying" will always be the first following by descending order of years
Array
(
[0] => 'Paying'
[1] => 2015
[2] => 2014
[3] => 2013
)
What is the simple way to do it in php? Thanks.
This should work for you:
(Here i simple use rsort()
)
<?php
$arr = array(2014, "Paying", 2013, 2015);
print_r($arr);
rsort($arr, SORT_STRING);
print_r($arr);
?>
Output:
//Before
Array ( [0] => 2014 [1] => Paying [2] => 2013 [3] => 2015 )
//After
Array ( [0] => Paying [1] => 2015 [2] => 2014 [3] => 2013 )