David
David

Reputation: 4508

adding to the name of the function some php variable

I have a function called check_nickname() And I want to write something like this

$ttt='nickname';
check_.$ttt();

How can I do it correct ?

Upvotes: 0

Views: 57

Answers (4)

Your Common Sense
Your Common Sense

Reputation: 157839

I would advise against that.

this will produce unmaintainable and undebuggable code.

I'd make one function which does all the verifications.

Upvotes: 3

user973254
user973254

Reputation:

$ttt = 'nickname';
$your_function = 'check_' . $ttt;

$your_function();

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

You would need to create another variable, such as $a = "check_".$ttt;, then call $a();

Upvotes: 1

Jon
Jon

Reputation: 437336

Create a variable that holds the function name, and apply parentheses to it:

$ttt='nickname';
$funcname = 'check_'.$ttt;
$funcname();

Upvotes: 2

Related Questions