Это действительно странно, и я просто не могу понять, почему это происходит.
Вот мой сценарий:
public function getWeatherConfig($lat =35.683, $lon=139.778, $elevation=10){
$weatherConfig_General = [
'latitude' => $lat,
'longitude' => $lon,
'elevation' => $elevation,
'hourly' => 'test',
'daily' => 'YYY',
'current' => 'XXX',
'temperature_unit' => null,
];
$count = count($weatherConfig_General);
$i = 1;
$query_string = '';
// Loop through the variables and check their values
foreach ($weatherConfig_General as $varName => $value) {
if ($value or $i < $count) {
$query_string .= $varName.'='.$value.'&'; // Add the variable name to the trueVars array if it's true
} else {
$query_string .= $varName.'='.$value; // do not add & on the last value.
}
$i++;
}
echo '
Подробнее здесь: https://stackoverflow.com/questions/791 ... from-doing