Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8590157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:13:50+00:00 2026-06-11T23:13:50+00:00

I have an array of cronjobs on my server, which I need to sort

  • 0

I have an array of cronjobs on my server, which I need to sort by the date they fire, the starting array is:

Array ( 
[0] => 00 08 24 10 * 2012 curl --user user:pass command 
[1] => 00 09 24 10 * 2012 curl --user user:pass command
[2] => 00 08 18 10 * 2012 curl --user user:pass command
[3] => 00 11 18 10 * 2012 curl --user user:pass command
)

I want this list represented in a table on my website, but sorted by month, day of month, hour, minute.

The desired output is:

Array(
[0] => 00 08 18 10 * 2012 curl --user user:pass command
[1] => 00 11 18 10 * 2012 curl --user user:pass command
[2] => 00 08 24 10 * 2012 curl --user user:pass command
[3] => 00 09 24 10 * 2012 curl --user user:pass command

Can anyone point me in the direction I need to go in order to achieve this?

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:13:51+00:00Added an answer on June 11, 2026 at 11:13 pm

    How about this?

    $a = array(
      '00 08 24 10 * 2012 curl --user user:pass command',
      '00 09 24 10 * 2012 curl --user user:pass command',
      '00 08 18 10 * 2012 curl --user user:pass command',
      '00 11 18 10 * 2012 curl --user user:pass command',
    );
    
    usort($a, function($f, $s) {
       $fx = implode('', array_reverse(preg_split('/\D+/', $f)));
       $sx = implode('', array_reverse(preg_split('/\D+/', $s)));
       return strcmp($fx, $sx);
    });
    
    var_dump($a);
    /*
    0 => string '00 08 18 10 * 2012 curl --user user:pass command' (length=48)
    1 => string '00 11 18 10 * 2012 curl --user user:pass command' (length=48)
    2 => string '00 08 24 10 * 2012 curl --user user:pass command' (length=48)
    3 => string '00 09 24 10 * 2012 curl --user user:pass command' (length=48)
     */
    

    What I’ve done here is basically extracting all the numeric parts from all the strings in question, then reversing them into a numeric string, then comparing these strings.

    This can be modified in two ways: first, hardening the regex so it won’t match numbers in command itself:

       $fx = implode('', array_reverse(
         preg_split('/(?<=\d{4}).+$|\D+/', $f)));
    

    … and second, using a memoizing function:

    function getSortCriteria($line) {
      static $criterias = array();
      if (! isset($criterias[$line])) {
        $numbers = preg_split('/\D+/', substr($line, 0, 18));
        $criterias[$line] = implode('', array_reverse($numbers));
      }
      return $criterias[$line];
    }
    
    usort($a, function($f, $s) { 
      return strcmp(getSortCriteria($f), getSortCriteria($s)); 
    });
    
    var_dump($a);    
    

    Here I removed the rest of the string with substring; it’s more efficient, I think. Still, showing how this can be done with regex might be useful as well. ))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have array object in jquery. array=[]; array{Id:user.Id,Date:user.Date}; Now am going to pass this
I have array that need to sort by their appearance, as they are written
I have array of 0's and 1's. And I need a function which return
i have array like below which is sorted by array_count_values function, Array ( [Session
I have a cronjob that get's updated when a (administrative) user sets a date.
I have array of objects: var aoo = [{},{},{},....{},{},{}]; I need a optimized function
I have array $arr=array(a=>array(b=>123)) and I need to do with it something like this:
I have array of element like this Cosmetics~Sample~test1, Cosmetics~Sample~test2, i need to display like
I have array like this: array('1224*', '543*', '321*' ...) which contains about 17,00 "masks"
I have array like below the page. I want to find array number which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.