1

我在将天气度数从华氏度更改为摄氏度时遇到了一些麻烦。

只有当我改变当前天气程度时它才能正常工作,但当我改变预测时它就不能正常工作。

有什么建议吗?

这是我的代码。

<h2>Today's weather</h2>
        <div class="weather">       
            <img src="<?= 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
            <span class="condition">
            <?= $current[0]->temp_f['data'] ?>&deg; F,
            <?= $current[0]->condition['data'] ?>
            </span>
        </div>
        <h2>Forecast</h2>
        <? foreach ($forecast_list as $forecast) : ?>
        <div class="weather">
            <img src="<?= 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
            <div><?= $forecast->day_of_week['data']; ?></div>
            <span class="condition">
                <?= $forecast->low['data'] ?>&deg; F - <?= $forecast->high['data'] ?>&deg; F,
                <?= $forecast->condition['data'] ?>
            </span>
        </div>  
        <? endforeach ?>
4

1 回答 1

2
function toCelsius($deg) {
    return ($deg-32)/1.8;
}

如果您在 F 中的温度在这里: $current[0]->temp_f['data']

那么你所要做的就是: toCelsius($current[0]->temp_f['data']

于 2011-11-09T15:24:14.233 回答