我知道這一定是一個基本問題。我google搜索,但無法找到我正在尋找什麼。PHP動態變量的簡單串聯 - 連接PHP變數
問題: 如何將動態變量加入到現有變量中。
比如...
我的代碼:
<?
// Gets value from url. In this example c is 1.
$c = $_GET[c];
// Multiple static questions will be pulled from a list.
// I use two as an example below.
$Q1 = "Is this question one?";
$Q2 = "so this must be question two then?"
echo "$c: ";
echo "Q$c"; // returns "Q1" but not the string above.
echo '$Q.$c"; // returns the val 1
?>
現在我猜你看到我的問題。 如何將兩者連接在一起並讓它返回適當的字符串?
謝謝:)
這是您正在運行的確切代碼嗎?你有一些bug - '$ _GET [c]'應該是'$ _GET ['c']',並且你在最後一行有不匹配的引號。請注意,如果你想在一個字符串中使用變量,你需要使用「而不是」。 –
它不是一個bug,但PHP的某種功能 - 首先它尋找c常量,如果它沒有找到 - 它使用它像一個字符串如果有錯誤報告,請注意錯誤 – kirugan
@kirugan是的,一個'功能'像魔術引號和自動提取(不記得實際名稱):p – Corbin