$names=get_defined_functions();
foreach($names["user"] as $f)
{
if(substr($f,0,6)=="_func1")
{
// now call $f
// call_user_func($f);
}
}
call all functions that have prefix
Domanda
Is it possible in PHP to call all functions that have a certain prefix ?
for example i have 70 functions most start with
func1.... func2 ....
i want to call all functions that start with _func1
is there any PHP function for that ? something like call_user_func but instead of a callback name to pass it something like '_func1*'
i know i can do it with 'get_defined_functions' but wonder if there's already such a function.
Soluzione
Altri suggerimenti
In case you are using methods from class, you can also use following :
for ex :
class myclass {
// constructor
function myclass()
{
return(true);
}
// method 1
function myfunc1()
{
return(true);
}
// method 2
function myfunc2()
{
return(true);
}
}
$class_methods = get_class_methods('myclass');
// or
$class_methods = get_class_methods(new myclass());
foreach ($class_methods as $method_name) {
echo "$method_name\n";
}
you can use sub string method in loop to get it working as per your need
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow