phpfunctionvariablesswitch-statementvbulletin

Return Results of a Function Within a Variable to Change the Varible


I am trying to pass a function into an existing variable to set specific locations within my template. However when I use the function switch I am not receiving any results.

function posicionnavbar($posicion) {
    switch ($posicion) {
        case 'top':
            return 'top';
        case 'soc':
            return 'soc';
        case 'nav':
            return 'nav';
        case 'usr':
            return 'usr';
    }
}

And the variable I am attempting to append to.

$omni[posicionnavbar($tabs['position'])] .= $nuevo_tab;

More Info:

$tabs['position']

Is either - top, soc, nav, or usr

$omni***

Is the variable used within my template for each location. IE: $omnitop

I have passed the variable using $omni .= $nuevo_tab; and using $omni within my template to confirm everything was working, with success. Which lead me to something being off with my function.

How can I pass my function into my variable to change the variable name?

end results would output one of the following:

$omnitop .= $nuevo_tab;
$omnisoc .= $nuevo_tab;
$omninav .= $nuevo_tab;
$omniusr .= $nuevo_tab;

Solution

  • I did manage to solve this.

    ${'omni'.posicionnavbar($tabs['position'])} .= $nuevo_tab;
    

    thanks to PHP Cookbook

    Knowing the proper symbols to link the variables together, I got rid of the switch and function altogether. The way I have this set up ${'omni'.$tabs['position']} .= $nuevo_tab; is enough to get the job done.