不知道這是否是一個WordPress問題,但我不這麼認爲。PHP內插變量作爲函數參數
我有一個while
循環,我遍歷用戶創建的內容循環,試圖獲得一個元字段,它具有與當前「鍵」相匹配的數字標識符(如果可以稱之爲,因爲這根本不是數組,所以用戶可以使用一些前端參數創建自定義循環。$this_label_url
通過插值方式請求人造「鑰匙」$this_label_url = get_post_meta($post->ID, 'instructor_{$number}_label_url', true);
。在這種情況下,變量插補不可能嗎?
<?php
$total_panels = get_post_meta($post->ID, 'total_panels', true); // set by the user with a custom meta value called "total_panels" (an integer)
$count = 1; // just a fake "key" for looping through my `while`
// create a faux "number" - simply takes $count and adds leading zero if not present
while ($total_panels >= $count) :
if ($count >= 9) {
$number = '0' . $count;
} else {
$number = $count;
}
$this_label_url = get_post_meta($post->ID, 'instructor_{$number}_label_url', true); // returns as an empty string,
把單引號'''改成雙引號''' – air4x