PHP - 在数组中显示 $ 语句

标签 php string wordpress

我有一个语句 $latest_pollid 并且想把它放在一个看起来像这样的数组中:

array(
        'comment_status'    =>  'open',
        'ping_status'       =>  'closed',
        'post_author'       =>  $author_id,
        'post_name'         =>  $slug,
        'post_title'        =>  $pollq_question,
        'post_status'       =>  'publish',
        'post_type'         =>  'post',
        'post_content'      =>   
    )

对于 post_content 项,我想将其设置如下: [投票 ID=$latest_pollid] 但我知道我不能按原样将这两者混为一谈。有什么方法可以将 $latest_pollid 中的值放在这个语句中吗? 'post_content' => '[poll id=xxxxxx]'

使用 sprint 类型的字符串可以做到这一点吗?

非常感谢任何帮助。

谢谢

最佳答案

尝试

'post_content' => '[poll id=' . $latest_pollid . ']'

array(
        'comment_status'    =>  'open',
        'ping_status'       =>  'closed',
        'post_author'       =>  $author_id,
        'post_name'         =>  $slug,
        'post_title'        =>  $pollq_question,
        'post_status'       =>  'publish',
        'post_type'         =>  'post',
        'post_content'      =>  '[poll id=' . $latest_pollid . ']'
    )

关于PHP - 在数组中显示 $ 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34432571/

相关文章:

java - 将 bytes[] 转换为字符串,然后再转换回 byte[] 时出现问题

string - 如何将字符串列表转换为方案中的一个字符串?

wordpress - "Access to Font..has been blocked by CORS policy"只有一个文件

java - char 和 int 交替字符串

php - 使用 jQuery 在 WordPress 中拉取随机横幅图像

javascript - Masonry 设置不影响 WP 后循环输出

php - 如何修复 302 重定向并使其成为 301?

javascript - 跨子域的 PHP $_SESSION

php - 为什么 codeigniter2 不以更安全的方式(例如 session )存储 csrf_hash?

javascript - 在 PHP 和 JavaScript 之间传递变量