Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个变量:
$my_var = page
并想将其放入数组中:
<?php $opts = array( 'page'=>'/subfolder/ <!-- $my_var ---> .php', ); content_custom('content-area', $opts); ?>
我会得到这样的路径:
/subfolder/page.php
我对php不是很熟悉。这可能吗?
$opts = array( 'page'=>"/subfolder/{$my_var}.php" );
那会很好用。但是,当您将字符串放在单引号中时,不会评估其中的变量。在您包含在字符串中的变量周围使用双引号,它将起作用。
您也可以使用 . 连接字符串的运算符:
尼尔的例子:
$opts = array( 'page'=>'/subfolder/'.$my_var.'.php' );