Posts Tagged ‘sort’
04
Jun

Recently I was talking about ksort() to sort array, but i forgot to mention the reversed method. (link)

krsort($ray);

This function sorts an array reversed. So Z – A instead of A – Z.

, , ,

31
May

A problem I encountered recently was, after a short search on the internet, easy to fix.
I was trying to arrange an array in php by it’s keys, but I didn’t know how at first. This is my array

$ray = array('2' => 'second', '1' => 'first', 'a' => 'alpha);

As you noticed the order is 2 – 1 – a. But i want to arrange it to 1 – 2 – a. The only thing I had to do was this:

ksort($ray);

Thats all you need to do. And it will arrange the array by key.

, , ,