Creating a function name on the fly (dynamically) - PHP
问题 Below is the code that I'm working with. function my_tab( $tabs ) { // the following array will be created dynamically $colors = array("red", "white", "blue"); foreach ($colors as $value) { $tabs[$value] = array( 'name' => $value ); // start creating functions function content_for_[$value]() { echo "this is the " .$value. " tab"; } // stop creating functions add_action('content_for_'.$value, 'content_for_'.$value); } return $tabs; } As you can see, I have an array that's created dynamically.