Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/20/2022 in all areas

  1. Example $arr = [ [ 'A', 'Jan. 22, 22'], [ 'B', 'Dec. 25, 21'], [ 'C', 'Feb. 22, 22'], [ 'D', 'Jan. 2, 22'] ]; usort($arr, function($a, $b) { $da = DateTime::createFromFormat('M. j, y', $a[1]); $db = DateTime::createFromFormat('M. j, y', $b[1]); return $db <=> $da; }); echo '<pre>' . print_r($arr, 1) . '</pre>'; outputs Array ( [0] => Array ( [0] => C [1] => Feb. 22 22 ) [1] => Array ( [0] => A [1] => Jan. 22 22 ) [2] => Array ( [0] => D [1] => Jan. 2 22 ) [3] => Array ( [0] => B [1] => Dec. 25 21 ) )
    1 point
  2. that date format is not directly sortable. where is this data coming from/stored at? you should store dates in a YYYY-MM-DD format, which will allow easy sorting by the date, then output the date in the format that you want when you display it. if this data is coming from a database, sort it in the sql query. if this data must be sorted in php, you would use php's usort() function, with a call-back function to sort on the date field. if that incoming date format cannot be corrected at the source, i would first convert the format, all at once, to be YYYY-MM-DD, then sort the data, then format the date back to that format when you display it.
    1 point
  3. change the code to use arrays for the sets of data under each major category, rather than processing each list/site separately. write two new functions (keeping the old code as is.) the new add_all_subscribers_lists_array() function would build arrays of parameters inside the inner foreach() loop, then call a new add_subscriber_list_array() function once, after the end of the inner foreach() loop. the code in the new add_subscriber_list_array() function would loop over the arrays of input parameters, query for the data and build each .csv file, then call the wp_mail() function once, supplying an array of the attachments. of some concern is that the code is creating a new database connection for each list/site. are all these databases on the same database server, with the only difference being which database is selected? if so, the code only needs to select the database before each query, rather than create an entirely new connection for each list/site query. for the 7warriors .csv, the posted code only outputs three headings, but there are four columns of data. to fix this, you would define a specific $column_names array inside the 7warriors conditional logic.
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.