PHP - displaying $ statement inside an array

I have a statement $latest_pollidand would like to put this inside an array that looks something like this:

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'      =>   
    )

For an element, post_contentI would like to set it as follows:   [poll id=$latest_pollid] But I know that I cannot mix these two as they are. Is there any way to place the value of $latest_pollidin in this expression?'post_content' => '[poll id=xxxxxx]'

Is a string of type sprint used ?

Any help is greatly appreciated.

thanks

+4
source share
1 answer

Try

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

or

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 . ']'
    )
+4
source

Source: https://habr.com/ru/post/1621409/


All Articles