Google Distance Matrixを使用して、タクシーのウェブサイトの2つの場所間の距離を計算しています。私は、場所の1つがロンドン空港であるかどうかを確かめるために条件をテストし、もしそうなら旅行の費用を計算するのではなくメッセージを返す必要があります。入れ子のPHP条件文の構造の問題
これは完全に昨日働いていましたが、今日は...コードは二重になりました。ピックアップとドロップオフの場所が両方の空港である場合にのみメッセージを返しますが、1つだけであれば、私の目的を凌駕する完全な距離のコストを計算しています。以下のコード構造であると私はstrpos()テストを開始するとき、私は39行で間違ったネストされた条件の構文を使用していますかどうかを疑問に思って....
if (isset($_POST['submitted'])):
$origin = urlencode($_POST['origin']);
$destination = urlencode($_POST['destination']);
// Insert encoded url variables
$url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=$origin&destinations=$destination&mode=driving&keyy={API KEY}";
$json = file_get_contents($url); // get the data from Google Maps API
$status = $result['rows'][0]['elements'][0]['status'];
if (status is OK):
// Calculate the distance
$status = ...;
$DistanceMetres = .....;
$Distance = .....; // converted to yards
// Calculate the Day Rate
....
// Calculate the Night Rate
....
// Calculate the Sunday Rate
....
// Calculate the Christmas & NYE Rate
....
// Set up variables for pick-up & drop-off locations
$toairport = $result['destination_addresses'][0];
$fromairport= $result['origin_addresses'][0];
if (distance is the minimum distance) {
echo the minimum cost of the trip
} else { //ie if the distance is more than the minimum distance
// Check to see if pick-up or drop-off destination is an airport
if (strpos($toairport, 'Heathrow') || strpos($toairport, 'Gatwick') || strpos($toairport, 'London Luton') || strpos($toairport, 'London City Airport') || strpos($fromairport, 'Heathrow') || strpos($fromairport, 'Gatwick') || strpos($fromairport, 'London Luton') || strpos($fromairport, 'London City Airport') === false) {
echo the cost of the trip
// But if at least one location is an airport
} else {
echo a message saying a special flat rate is available for airport transfers
}
}
else:
echo that status is not okay
endif;
else:
display input form
endif;
if文の最後の 'strpos()'は '=== false'でなければならないのはなぜですか?私は何かを逃していますか? また、文字列の位置0に文字列がある場合、 'if(0)'は決してtrueになりません。 – Henders
最低距離計算を行う前に必ず空港を確認してください – RiggsFolly