sort - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of sort.php

  1. <?php
  2.  
  3. $arr = [
  4.     0 => [
  5.         'date' => '12/10/2018',
  6.                 'info' => 'aaa',
  7.                 'exclude' => true
  8.     ],
  9.         1 => [
  10.             'date' => '12/08/2018',
  11.         'info' => 'bbb',
  12.                 'exclude' => true
  13.     ],
  14.     2 => [
  15.         'date' => '12/12/2018',
  16.         'info' => 'ccc'
  17.     ],
  18.     3 => [
  19.         'date' => '12/07/2018',
  20.         'info' => 'ddd'
  21.     ],
  22.     4 => [
  23.         'date' => '12/14/2018',
  24.         'info' => 'eee'
  25.     ],
  26.     5 => [
  27.         'date' => '12/05/2018',
  28.         'info' => 'fff'
  29.     ]
  30. ];
  31.  
  32. function sortFunction($a, $b) {
  33.     return strtotime($a['date']) - strtotime($b['date']);
  34. }
  35.  
  36. usort($arr, 'sortFunction');
  37.  
  38. var_dump($arr);
File Description
  • sort
  • PHP Code
  • 13 Apr-2018
  • 631 Bytes
You can Share it: