Jump to content

php function use parameter if set


ttmt-73

Recommended Posts

Hi all

 

Is it possible to have a function with two parameters but and then check if one is passed before using it.

 

In this code here I want to remove spaces and change to lowercase.

 

If the $extra parameter is set I want to add that to the end of the string.

 

 


function className($nametoUse, $extra){
    $noSpace = str_replace(' ', '', $nametoUse);
    $toLower = strtolower($noSpace);
 
    if(!empty($extra)){
        $classtoUse = $toLower." ".$extra;
    }else{
        $classtoUse = $toLower;
    }
 
    return $classtoUse; 
  }

 

 

Link to comment
https://forums.phpfreaks.com/topic/291500-php-function-use-parameter-if-set/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.