我使用我的简单的项目,从另一个PHP文件获取变量名称。有些变量具有相同的价值..PHP的 - foreach跳过,如果结果是相同的值
我用的foreach显示在特定目录不同的PHP文件变量..
(1st app_config.php) $app_name = "Pass Generator";
(2nd app_config.php) $app_name = "Random Name Generator";
(3rd app_config.php) $app_name = "Love Meter";
(4th app_config.php) $app_name = "Random Name Generator";
(5th app_config.php) $app_name = "Lucky Number Generator";
由于我的第2和$ APP_NAME的第四变量相同的值,我怎么能跳过其中之一。因此,输出将是:
Pass Generator
Random Name Generator
Love Meter
Lucky Number Generator
这是我的代码:
$path = '../../apps/' . $name[0];
$results = scandir($path);
foreach ($results as $result) {
if ($result === '.' or $result === '..') continue;
if (is_dir($path . '/' . $result)) {
require_once("../../apps/".$result."/app_config.php");
$app .= $app_name."<Br>";
}
}
echo $app_name;
有人吗?由于
我建议你HTTP: // foreach循环之前的//php.net/manual/en/function.array-unique.php(ps:foreach比while慢)。 – HellBaby 2014-12-07 04:06:20