可以动态更改 PHP foreach 循环的数组表达式


Is is possible to change dynamically the array expression of a PHP foreach loop?

我有几个存储页面配置的数组,它们具有相同的索引和其他类似的配置。他们的名字后面总是跟着Config

$welcomeConfig = array (
  "title" => "welcome to my website",
  "other_settings"
);
$contactsConfig = array (
  "title" => "contact us",
  "other_settings"
);

由于我不想使用自定义foreach loop对每个页面进行硬编码,因此我想知道是否可以定义一个变量,将其与Config字符串连接起来,然后将其用作数组表达式。

我尝试了这种方式:

$custom = "welcome";
$custom .= "Config";
foreach ($custom as $config) {
  echo $config;
}

但它不起作用。

有没有办法做到这一点?

<?php
$custom = "welcome";
$custom .= "Config";
foreach ($$custom as $config)
{
    echo $config;
}
?>

http://php.net/manual/en/language.variables.variable.php