15 lines
		
	
	
		
			486 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			15 lines
		
	
	
		
			486 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
function explode_list(string $str) : array {
 | 
						|
    return explode(",", str_replace(" ", "", $str));
 | 
						|
}
 | 
						|
 | 
						|
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);
 | 
						|
    }
 | 
						|
}
 |