19 lines
		
	
	
		
			613 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			19 lines
		
	
	
		
			613 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
function explode_list(string $str) : array {
 | 
						|
    if (($str = trim($str, " \n\r\t\v\0,")) !== "") {
 | 
						|
        return array_map(fn($a) => trim($a), 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);
 | 
						|
    }
 | 
						|
}
 |