Defining a function with name from a variable?
I need to create a column-system for Wordpress with shortcodes, which is not a problem, but I'm trying to make it with less code.

I have an array with the data needed, I loop through it, create a unique-named function and set it as shortcode-function. The third step is a mystery. How can I create a function from a variable.

Here's an example, how it should be done:
    
    $data[] = "first";
    $data[] = "second";
    foreach($data as $key => $value) {
    	function $value($atts,$content) {
    		return '<div class="'.$value.'">'.$content.'</div>';
    	}
    	add_shortcode($value,$value);
    }

However, it seems that it's not possible to make it work like that in PHP. Is there any way to make this work, as I would not want to write all the (identical) functions separated. I could make the shortcode something like `[col first]text[/col]` but the client wants to have different names for every one of them.

I would appreciate any help!

Thanks,
Martti Laine
Defining a function with name from a variable?
===

I need to create a column-system for Wordpress with shortcodes, which is not a problem, but I'm trying to make it with less code.

I have an array with the data needed, I loop through it, create a unique-named function and set it as shortcode-function. The third step is a mystery. How can I create a function from a variable.

Here's an example, how it should be done:
    
    $data[] = "first";
    $data[] = "second";
    foreach($data as $key => $value) {
    	function $value($atts,$content) {
    		return '<div class="'.$value.'">'.$content.'</div>';
    	}
    	add_shortcode($value,$value);
    }

However, it seems that it's not possible to make it work like that in PHP. Is there any way to make this work, as I would not want to write all the (identical) functions separated. I could make the shortcode something like `[col first]text[/col]` but the client wants to have different names for every one of them.

I would appreciate any help!

Thanks,
Martti Laine