public static function sortByPriority(Array $originalArray, Array $priority, $strictMatch = true)
  {
    // The priority array
    $priorityArray = [];

    // For each priority array index
    foreach ($priority as $priorityElement) {

      // Get priority key and valye
      foreach ($priorityElement as $priorityKey => $priorityValue) {

        // Now scan the original array
        foreach ($originalArray as $originalElementKey => $originalElement) {

          // Get original key and valye
          foreach ($originalElement as $originalKey => $originalValue) {

            // Set match
            $isMatch = false;

            // Exact match
            // If keys and values match exactly
            if ($strictMatch === true && $priorityKey === $originalKey && $priorityValue === $originalValue) {
              $isMatch = true;
            }

            // "Loose" match
            // If keys and values match without taking type into account or case sensitivity
            if ($strictMatch === false && strcasecmp($priorityKey, $originalKey) === 0 && strcasecmp($priorityValue, $originalValue) === 0) {
              $isMatch = true;
            }

            // If we have a match
            if ($isMatch) {

              // Add to priority array
              $priorityArray[] = $originalElement;

              // Unset this element from original array
              unset($originalArray[$originalElementKey]);
            }
          }
        }
      }
    }

    // Merge both the priority and original arrays with priority on top
    return array_merge($priorityArray, $originalArray);
  }