여기에서 바로 생각해보십시오. forecast_conditions
의 정확한 금액을 계산하는 코드가 4 개 있습니다. (count($condition) -1) <= 4 ? ', ' : ', eller '
.count (data)가 4보다 작거나 같은 경우 인쇄하십시오. 그렇지 않으면 두 개를 인쇄하십시오. 작동하지 않습니다.
count($condition)
인쇄물 5
그래서 거기에 마이너스 부호가 있어야합니다. $condition
은 foreach
에 있으므로 콘텐츠를 루프 할 수 있습니다 forecast_conditions
; foreach($whome_answer[weather][forecast_conditions] AS $condition) {
.
위의 코드는 onsdag, torsdag, fredag, lördag,
을 인쇄합니다. 이것은 잘못되었습니다. 내가 원하는 방법은 다음과 같습니다. onsdag, torsdag, fredag, eller lördag
하지만 코드에서 제대로 이해할 수 없습니다! 모든 종류의 솔루션 (== 4,> = 4,! = 4, < 4 등)을 테스트했습니다.
어떻게하면 제대로 작동합니까?
미리 감사드립니다. http://www.google.com/ig/api?weather=,,,59378217,13504219&hl=en
EDIT (솔루션하지만 또 하나 개의 문제) 코드 : 여기
foreach($whome_answer[weather][forecast_conditions] AS $condition) {
# KONTROLL
if(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'mån') {
$day = 'måndag';
# KONTROLL
} elseif(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'tis') {
$day = 'tisdag';
# KONTROLL
} elseif(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'ons') {
$day = 'onsdag';
# KONTROLL
} elseif(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'tors') {
$day = 'torsdag';
# KONTROLL
} elseif(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'fre') {
$day = 'fredag';
# KONTROLL
} elseif(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'lör') {
$day = 'lördag';
# KONTROLL
} elseif(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'sön') {
$day = 'söndag';
}
echo '<a href="javascript:void(0)" class="forecast-link">';
echo $day;
echo '</a>';
echo (count($condition) -1) <= 4 ? ', ' : ', eller ';
}
내가에서 콘텐츠를 가져 오는 링크입니다 : 여기에 편집
루프입니다 아래는 해결책이지만 지금은 찾고 있던 것 대신에 onsdag, torsdag, fredag, eller lördag,
을 인쇄하고 있습니다. "lördag"다음에 마지막 쉼표를 제거하려면 어떻게해야합니까? 'if 태그'뒤에 $i
을 포함하면 모양이 어떻게됩니까 : onsdag, 2torsdag, 3fredag, eller 4lördag, 5
.
어떻게이 문제를 해결할 수 있습니까?
$i = 1;
foreach($whome_answer[weather][forecast_conditions] AS $condition) {
$i++;
# KONTROLL
if(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'mån') {
$day = 'måndag';
# KONTROLL
} elseif(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'tis') {
$day = 'tisdag';
# KONTROLL
} elseif(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'ons') {
$day = 'onsdag';
# KONTROLL
} elseif(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'tors') {
$day = 'torsdag';
# KONTROLL
} elseif(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'fre') {
$day = 'fredag';
# KONTROLL
} elseif(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'lör') {
$day = 'lördag';
# KONTROLL
} elseif(utf8_decode($condition['day_of_week']['@attributes']['data']) == 'sön') {
$day = 'söndag';
}
echo '<a href="javascript:void(0)" class="forecast-link">';
echo $day;
echo '</a>';
echo $i != 4 ? ', ' : ', eller ';
}
잘 모르겠습니다. 카운트의 오해와 같은 것 같습니다. "count (data)가 4보다 작거나 같으면 count ($ data) <= 4입니다. -1이 어디에서 왔는지 확실하지 않습니다. – Corbin
전체 질문을 읽어보십시오. – Erik
<대신 <= – jack