Cколько у вас всего юзеров, если вы можете каждому лично дать аттрибуты?
function qmn_variable_average_category_points($content, $mlw_quiz_array)
{
$return_points = 0;
while (strpos($content, '%AVERAGE_CATEGORY_POINTS%') !== false || false !== strpos($content, '%AVERAGE_CATEGORY_POINTS_')) {
$return_points = 0;
$total_questions = 0;
preg_match("~%AVERAGE_CATEGORY_POINTS%(.*?)%/AVERAGE_CATEGORY_POINTS%~i", $content, $answer_text);
if (empty($answer_text)) {
$category_name = mlw_qmn_get_string_between($content, '%AVERAGE_CATEGORY_POINTS_', '%');
} else {
$category_name = $answer_text[1];
}
foreach ($mlw_quiz_array['question_answers_array'] as $answer) {
if ($answer["category"] == $category_name) {
$total_questions += 1;
$return_points += $answer["points"];
}
}
// Как расчитать процент одного числа от другого
$percent = ($return_points / $total_questions) * 100;
if ($total_questions !== 0) {
$return_points = round($return_points / $total_questions, 2);
} else {
$return_points = 0;
}
if (empty($answer_text)) {
$content = str_replace('%AVERAGE_CATEGORY_POINTS_' . $category_name . '%', $return_points, $content);
} else {
$content = str_replace($answer_text[0], $return_points, $content);
}
}
return $content;
}
..
type
TAppender<T> = class
class procedure Append(var Arr: TArray<T>; Value: T);
end;
..
{ TAppender<T> }
class procedure TAppender<T>.Append(var Arr: TArray<T>; Value: T);
begin
SetLength(Arr, Length(Arr)+1);
Arr[High(Arr)] := Value;
end;
...
procedure TMainForm.ButtonClick(Sender: TObject);
var
men: TMatchCollectionEnumerator;
a: TArray<string>;
begin
men := TRegEx.Matches('one two three', '\w+').GetEnumerator;
while men.MoveNext do
begin
TAppender<string>.Append(a, men.Current.Value);
end;
men.Free;
end;