Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP插值变量作为函数参数_Php_Wordpress_Variables_Syntax_Interpolation - Fatal编程技术网

PHP插值变量作为函数参数

PHP插值变量作为函数参数,php,wordpress,variables,syntax,interpolation,Php,Wordpress,Variables,Syntax,Interpolation,不确定这是否是WordPress的问题,但我不这么认为 我有一个while循环,在这个循环中,我迭代用户创建的内容循环,并尝试获取一个元字段,该元字段具有与当前“键”匹配的数字标识符(如果您可以这样称呼它,因为这根本不是一个数组,用户只需使用一些前端参数创建一个自定义循环。$this\u label\u url通过插值请求人造“键”$this\u label\u url=get\u post\u meta($post->ID,'讲师{$number}\u label\u url',true);。

不确定这是否是WordPress的问题,但我不这么认为

我有一个
while
循环,在这个循环中,我迭代用户创建的内容循环,并尝试获取一个元字段,该元字段具有与当前“键”匹配的数字标识符(如果您可以这样称呼它,因为这根本不是一个数组,用户只需使用一些前端参数创建一个自定义循环。
$this\u label\u url
通过插值请求人造“键”
$this\u label\u url=get\u post\u meta($post->ID,'讲师{$number}\u label\u 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, 

这是可能的,但您需要使用双引号;单引号不会被解析为插值

$this_label_url = get_post_meta($post->ID, "instructor_{$number}_label_url", true);

将单引号
改为双引号
谢谢-其中一个讨厌的“gotcha's”。我想我是一个讨厌喜欢单引号的人,我知道总有一天我会喜欢单引号的。@Brian它们有一个时间和地点,比如当你想在字符串中输入一个文本
$
,而不需要转义。