Search code examples
phpphp-5.3

call all functions that have prefix


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.


Solution

  • $names=get_defined_functions();
    foreach($names["user"] as $f)
    {
      if(substr($f,0,6)=="_func1")
       {
           // now call $f
          //  call_user_func($f);
       }
    
    }