usort

This function is a wrapper for the usort function in PHP. It allows you to do custom sorting from within PINP templates.

The function takes 2 arguments:

array: array to be sorted.
$sort_func: function created using util::create_function
returnvalue: sorted array

Example for sorting an array containing RSS articles on the field 'pubDate':

  load("mod_util.php");





  $sort_func = util::create_function(
   '$a, $b',
   '$time_a_arr = explode("GMT", $a["pubDate"]);
    $time_a = strtotime($time_a_arr[0]);
    $time_b_arr = explode("GMT", $b["pubDate"]);
    $time_b = strtotime($time_b_arr[0]);
   if ($time_a > $time_b) {
    return false;
   } else {
    return true;
   }'
  );
  util::usort($rss, $sort_func);