Slug输入字段检查功能无法正常工作

My slug url is made of title so I have basic Slug function and one of my own who checking slug input field is/not empty and do some action, but it doesn't work properly.. so maybe someone have some ideas what am I doing wrong?!

here is basic slug function:

function slug($text){ 

    // replace non letter or digits by -
    $text = preg_replace('~[^\pL\d]+~u', '-', $text);

    // transliterate
    $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

    // remove unwanted characters
    $text = preg_replace('~[^-\w]+~', '', $text);

    // trim
    $text = trim($text, '-');

    // remove duplicated - symbols
    $text = preg_replace('~-+~', '-', $text);

    // lowercase
    $text = strtolower($text);

    if (empty($text)) {
      return 'n-a';
    }

    return $text;
}

here is function I wrote (which doesn't work properly) :

function filterSlug($ax, $bx){
    if(isset($_POST[$ax]) && $_POST[$ax] != ''){
        $ax = slug($ax);
    } else {
        $ax = slug($bx);
    }
    }

I call it out :

filterSlug($postSlug, $postTitle);

here is code I duplicate in other pages :

if(isset($_POST['postSlug']) && $_POST['postSlug'] != ''){
                    $postSlug = slug($postSlug);
                } else {
                    $postSlug = slug($postTitle);
                } 

this one works correctly.

You must to return something from you function:

function filterSlug($ax, $bx){
    if(isset($_POST[$ax]) && $_POST[$ax] != ''){ 
        $ax = slug($ax);
    } else { 
        $ax = slug($bx);
    }
    return $ax;
}