severndigital Posted October 19, 2009 Share Posted October 19, 2009 this might be impossible, but i had an idea and can't seem to find if it is possible. I have a quite a few of functions that I need to call based on the content of a variable. all the functions are basically named the same except for the content of the variable. can I load the variable as part of the function name?? here is some code that might help to explain it better. $variable = $_POST['renderIntent']; //this can be a bunch of different things we'll say HTML for this example. render_$variable_info(); // which would translate to render_HTML_info(); i know the easiest way would be to make an if else and go through all the functions. but there are more than a few possibles. Unfortunately this is how the code is now, and I'm trying to make the best of crappy situation. any help would be great. Thanks, Link to comment https://forums.phpfreaks.com/topic/178267-solved-variable-function-name/ Share on other sites More sharing options...
Michdd Posted October 19, 2009 Share Posted October 19, 2009 Not exactly like that, but you can do this: $variable = $_POST['renderIntent']; $func = "render_" . $variable . "_info"; $func(); Link to comment https://forums.phpfreaks.com/topic/178267-solved-variable-function-name/#findComment-939951 Share on other sites More sharing options...
severndigital Posted October 19, 2009 Author Share Posted October 19, 2009 that will work, I was just trying to save myself from writing a really long if statement. thanks plenty. C Link to comment https://forums.phpfreaks.com/topic/178267-solved-variable-function-name/#findComment-939955 Share on other sites More sharing options...
jonsjava Posted October 19, 2009 Share Posted October 19, 2009 If you're worried about if statements, why not use a switch? Link to comment https://forums.phpfreaks.com/topic/178267-solved-variable-function-name/#findComment-939956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.