I have an array with academic years:
$arrayAcademicYears = array(
array("8889", "1988-1989"),
array("8990", "1989-1990"),
array("9091", "1990-1991"),
array("0405", "2004-2005"),
array("1112", "2011-2012"),
array("1213", "2012-2013")
);
foreach($arrayAcademicYears as $k => $v) {
echo "KEY: ";
echo $v[0];
echo " -> VALUE: ";
echo $v[1];
echo "<br>";
}
This prints:
KEY: 8889 -> VALUE: 1988-1989
KEY: 8990 -> VALUE: 1989-1990
KEY: 9091 -> VALUE: 1990-1991
KEY: 0405 -> VALUE: 2004-2005
KEY: 1112 -> VALUE: 2011-2012
KEY: 1213 -> VALUE: 2012-2013
Then I have the current academic year in a variable like this:
$currentAcademicYear="1112";
How can I change the code to print:
KEY: 1112 -> VALUE: 2011-2012
KEY: 1213 -> VALUE: 2012-2013
KEY: 0405 -> VALUE: 2004-2005
KEY: 9091 -> VALUE: 1990-1991
KEY: 8990 -> VALUE: 1989-1990
KEY: 8889 -> VALUE: 1988-1989
Please note that this is just an example, I’m not asking for a solution to any kind of academic course exercise. Just a self taught PHP learner here.
Thanks a lot! (.. for helping me becoming a better PHP programmer :))
This will reverse your array, displaying the newest first:
Place it just above:
Array_reverse will for some reason change the key’s on all your items to 0 increment, except for the 04-05 year. Use the following function which is updated and will achieve the correct sorting.
Usage would be as:
So add the function block to your code, and then replace:
With
The resulting array would look like: