Sorting Arrays in PHP

sortrsortksortkrsortasortarsortnatsortnatcasesort
Задание 1

Given an array:

php<?php
  $arr = ['3'=>'a', '2'=>'d', '1'=>'c', '5'=>'e', '4'=>'b'];
?>

Sort the array in ascending order by values. This is what you should get:

php['3'=>'a', '4'=>'b', '1'=>'c', '2'=>'d', '5'=>'e'];
Задание 2

Given an array:

php<?php
  $arr = [10, 2, 35, 4, 15];
?>

Sort the array in descending order by values. This is what you should get:

php[35, 15, 10, 4, 2];
Задание 3

Given an associative array:

php<?php
  $arr = ['z'=>'a', 'y'=>'d', 'x'=>'c', 'w'=>'b'];
?>

Sort the array in ascending order by keys. This is what you should get:

php['w'=>'b', 'x'=>'c', 'y'=>'d', 'z'=>'a'];
Задание 4

Given an associative array:

php<?php
  $arr = ['a'=>1, 'c'=>3, 'b'=>2, 'e'=>5, 'd'=>4];
?>

Sort the array in descending order by keys. This is what you should get:

php['e'=>5, 'd'=>4, 'c'=>3, 'b'=>2, 'a'=>1];
Задание 5

Given an array:

php<?php
  $arr = ['a'=>5, 'b'=>2, 'c'=>4, 'd'=>1, 'e'=>3];
?>

Sort the array in ascending order by values, preserving the keys. This is what you should get:

php['d'=>1, 'b'=>2, 'e'=>3, 'c'=>4, 'a'=>5];
Задание 6

Given an array:

php<?php
  $arr = ['a'=>10, 'b'=>40, 'c'=>20, 'd'=>30];
?>

Sort the array in descending order by values, preserving the keys. This is what you should get:

php['b'=>40, 'd'=>30, 'c'=>20, 'a'=>10];
Задание 7

Given an array:

php<?php
  $arr = ['img12.png', 'img10.png', 'img2.png', 'img1.png'];
?>

Sort the array using "natural" sorting. This is what you should get:

php['img1.png', 'img2.png', 'img10.png', 'img12.png'];
Задание 8

Given an array:

php<?php
  $arr = ['IMG12.png', 'img10.png', 'img2.png', 'IMG1.png'];
?>

Sort the array using case-insensitive "natural" sorting. This is what you should get:

php['IMG1.png', 'img2.png', 'img10.png', 'IMG12.png'];