3

I have a variable:

$my_var = page

And want to put it into an array:

 <?php 
    $opts = array(
        'page'=>'/subfolder/ <!-- $my_var ---> .php',
    );
    content_custom('content-area', $opts); 
?>

That I will get the path like:

/subfolder/page.php

I'm not so familiar with php. Is this possible?

3 Answers 3

8
$opts = array(
    'page'=>"/subfolder/{$my_var}.php"
);
Sign up to request clarification or add additional context in comments.

1 Comment

@Melros no problem ^_^ happy to help
3

That will work fine. However, when you put a string in SINGLE quotes, variables inside it aren't evaluated. Use double quotes around the variable you're including in the string, and it will work.

Comments

2

You can also use the . operator to concatenate strings:

Neal's example:

$opts = array(
    'page'=>'/subfolder/'.$my_var.'.php'
);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.