2010-03-24 136 views
0

我在我的配置文件中設置了一個數組,我在我的函數中使用了全局變量。
這工作正常,但現在我想在我的函數中將此數組的名稱作爲@參數傳遞。
變量中的PHP變量

// in config file: 
$album_type_arr = array("appartamento", "villa"); 

global $album_type_arr; // pull in from db_config 
echo $album_type_arr[0]; 

function buildmenu($name) { 
    $test = global $name . "_arr"; 
    echo $test[0]; 
} 
buildmenu("album_type"); 
+0

你的問題是? – 2010-03-24 11:09:52

+0

你不能直接將你的數組傳遞給你的函數嗎? 'buildmenu($ album_type_arr);' – 2010-03-24 11:11:15

+0

也許,但我需要這個名字的其他東西,值等tnx無論如何。 – FFish 2010-03-24 11:19:40

回答

0

您可以使用 「variable variables」。此作品:

function buildmenu($name) { 
    global ${$name. '_arr'}; 
    $test = ${$name. '_arr'}; 
    echo $test[0]; 
}