繁体   English   中英

有可能动态更改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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM