SpreadQuiz/common_func.php

19 lines
557 B
PHP

<?php
function explode_list(string $str) : array {
if (trim($str) !== "") {
return explode(",", str_replace(" ", "", $str));
} else {
return [];
}
}
function alter_array_contents(array &$a, $add, $remove) {
if (($add !== null) && !array_search($add, $a)) { // if user was not assigned to the corresponding group
$a[] = $add;
}
if (($remove !== null) && (($i = array_search($remove, $a)) !== false)) { // only perform deleting if user is assigned to the passed group
array_splice($a, $i, 1);
}
}