Keeping the previous get value and add another value when submitted

Here is the answer to my question

<?php
    // If there is a value to filter
    if($_GET['filter']) {
        // $urlHasFilter = true;
        // Create an array out of query string of the filters example (issues,voices)
        $urlFilters = explode(',', $_GET['filter']);
    } else {
        // $urlHasFilter = false;
        // if filter has nothing create an empty array
        $urlFilters = array();
    }
    $isAll="";
    // if filter = all add class active to that link
    if($_GET['filter'] == 'all') {
        $isAll="active";
    }
?>


<ul>
    <li><a href="https://wordpress.stackexchange.com/questions/214402/?filter=all" class="<?php echo $isAll; ?>">All</a></li>
    <?php
        $args = array(
            'orderby' => 'name',
            'parent' => 0,
            // 'exclude' => 3,
        );

        $categories = get_categories($args);
        // loop through the categorys that are being used.
        foreach ( $categories as $category ) {
            $class = "";
            $active = false;
            $urlFiltersMinus = array();
            // Loop through the array of query strings
            foreach($urlFilters as $urlFilter) {
                // Added class "active" if matches that Category slug
                if($urlFilter == $category->slug) {
                    $class = "active";
                    $active = true;
                } else {
                    $urlFiltersMinus[] = $urlFilter;
                }
            }
            if($active) {
                $url = implode(',', $urlFiltersMinus);
            } else {
                $urlFiltersMinus[] = $category->slug;
                $url = implode(',', $urlFiltersMinus);
            }
            echo '<li><a href="?filter=".$url.""class=".$class."value="'.$url.'">'.$category->name.'</a></li>';
        }
    ?>
</ul>