[英]PHP elseif statement not working
我目前正在使用wordpress開發一個使用FSQM Pro測驗插件的網站。 插件使用格式字符串%DESIGNATION%來顯示用戶在完成測驗時獲得的排名。
我正在嘗試編寫一些php,它將根據用戶達到的排名輸出不同的文本,但由於某種原因,它什么也沒有輸出。 我的代碼在下面,有人可以幫忙嗎?
此代碼段位於單獨的php文件$format_string_components = $this->get_format_string();
<?php
$a="Ranking 1";
$b="Ranking 2";
$c="Ranking 3";
$d="Ranking 4";
if ($format_string_components['%DESIGNATION%'] == $a) {
echo 'text 1';
} elseif ($format_string_components['%DESIGNATION%'] == $b) {
echo 'text 2';
} elseif ($format_string_components['%DESIGNATION%'] == $c) {
echo 'text 3';
} elseif ($format_string_components['%DESIGNATION%'] == $d) {
echo 'text 4';
} else {
echo '<p>Your result was not found.</p>';
}
?>
更改“
到"
。刪除空格<? php
<?php
$a="Ranking 1";
$b="Ranking 2";
$c="Ranking 3";
$d="Ranking 4";
if ($format_string_components['%DESIGNATION%'] == $a) {
echo "text 1";
} elseif ($format_string_components['%DESIGNATION%'] == $b) {
echo "text 2";
} elseif ($format_string_components['%DESIGNATION%'] == $c) {
echo "text 3";
} elseif ($format_string_components['%DESIGNATION%'] == $d) {
echo "text 4";
} else {
echo "<p>Your result was not found.</p>";
}
?>
由於您使用了引號,因此無法正常工作。 將引號更改為“”。 喜歡
if ($format_string_components['%DESIGNATION%'] == $a) {
echo "text 1";
} elseif ($format_string_components['%DESIGNATION%'] == $b) {
echo "text 2";
} elseif ($format_string_components['%DESIGNATION%'] == $c) {
echo "text 3";
} elseif ($format_string_components['%DESIGNATION%'] == $d) {
echo "text 4";
} else {
echo "<p>Your result was not found.</p>";
}
還要避免<?php
標記中的空格。
<?php
$a="Ranking 1";
$b="Ranking 2";
$c="Ranking 3";
$d="Ranking 4";
if ($format_string_components['%DESIGNATION%'] == $a) {
echo 'text 1';
} elseif ($format_string_components['%DESIGNATION%'] == $b) {
echo 'text 2';
} elseif ($format_string_components['%DESIGNATION%'] == $c) {
echo 'text 3';
} elseif ($format_string_components['%DESIGNATION%'] == $d) {
echo 'text 4';
} else {
echo '<p>Your result was not found.</p>';
}
?>
更改引號(“)並從中刪除空格
<? php
代碼使用它:
<?php
$a="Ranking 1";
$b="Ranking 2";
$c="Ranking 3";
$d="Ranking 4";
if ($format_string_components['%DESIGNATION%'] == $a) {
echo "text 1";
} elseif ($format_string_components['%DESIGNATION%'] == $b) {
echo "text 2";
} elseif ($format_string_components['%DESIGNATION%'] == $c) {
echo "text 3";
} elseif ($format_string_components['%DESIGNATION%'] == $d) {
echo "text 4";
} else {
echo "<p>Your result was not found.</p>";
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.