首页 > 解决方案 > 我在回显的 switch 语句中的变量的 PHP '注意:未定义变量'错误

问题描述

我的 PHP 中有这个错误,我似乎不明白为什么:

注意:未定义变量:第 12 行 C:\xampp\htdocs\ws5\process.php 中的站点

我似乎在我的 switch 语句中回显的每个变量都得到了它

我的代码是:

<?php
$horfield = file_get_contents("http://www.martynhicks.uk/weather/clientraw.txt");
$thornbury = file_get_contents("http://www.thornburyweather.co.uk/weatherstation/clientraw.txt");
$gloucestershire = file_get_contents("https://www.glosweather.com/clientraw.txt");
$newquay = file_get_contents("http://www.newquayweather.com/clientraw.txt");

if (isset($_GET['site'])){
  $site = $_GET['site'];
}
switch ($site) {
  case 'Horfield':
echo $horfield;
break;
  case 'Thornbury':
echo $thornbury;
break;
  case 'Glouc':
echo $gloucestershire;
break;
  case 'Newquay':
echo $newquay;
break;
}
?>

(第 12 行是第一个 echo 语句 'echo $horfield',其他 3 行也是如此。]

谢谢

标签: phpswitch-statement

解决方案


推荐阅读