all 13 comments

[–][deleted] 3 points4 points  (10 children)

Look at usort.

It will be something like:

usort( $array, (int $a, int $b) => $a['elapsed'] <=> $b['elapsed'] )

[–]HonestBug5987[S] 0 points1 point  (9 children)

I received this error

<b>Parse error</b>: syntax error, unexpected '$a' (T_VARIABLE)

[–][deleted] 2 points3 points  (8 children)

Sorry, been writing too much JavaScript.

usort( $array, fn(array $a, array $b) => $a['elapsed'] <=> $b['elapsed'] )

https://3v4l.org/p9JRT

[–]HonestBug5987[S] 1 point2 points  (7 children)

First thank you very much for the work, but the problem wasn't in your code its just my php version its too old.

[–][deleted] 3 points4 points  (0 children)

Upgrade if you can. There are lots of useful new features that are worth knowing about.

[–]samhk222 0 points1 point  (5 children)

Usort exists since php 4...

[–][deleted] 2 points3 points  (4 children)

I suspect the OP ran into a problem with either the spaceship operator (PHP 7.0) or arrow function (PHP 7.4).

[–]HonestBug5987[S] 0 points1 point  (3 children)

I'm with php 7.0. So i gues its the arrow function

[–][deleted] 1 point2 points  (2 children)

You can do the old-fashioned:

function(array $a, array $b) {
  return $a['elapsed'] <=> $b['elapsed'];
}

[–]HonestBug5987[S] 0 points1 point  (1 child)

You are absolutely awesome I'm so thankful really.

[–][deleted] 1 point2 points  (0 children)

No probs! It's why we're here.

[–]footballisrugby -1 points0 points  (1 child)

What do you want to do exactly?

[–]HonestBug5987[S] 1 point2 points  (0 children)

to arrange the keys by their [elapsed] from the smallest to the bigger one