Php 回显单引号数组';s值在另一个单引号数组值中

Php 回显单引号数组';s值在另一个单引号数组值中,php,Php,当最后一个值显示在我的屏幕上时,我试图在“test2”的输出中回显“test”的值,但没有运气。 我做的每一个测试都没有返回文本中的基本测试,所以我确信我遗漏了一些关键的东西 任何帮助都将不胜感激。 以下是我的数组代码: 'test' => 'BASICTEST', 'test2' => "<div id=\"secondary\">secondary test made after 'test'</div>" “测试”=>“基本测试”, 'test2'=>

当最后一个值显示在我的屏幕上时,我试图在“test2”的输出中回显“test”的值,但没有运气。 我做的每一个测试都没有返回文本中的基本测试,所以我确信我遗漏了一些关键的东西

任何帮助都将不胜感激。 以下是我的数组代码:

'test' => 'BASICTEST',
'test2' => "<div id=\"secondary\">secondary test made after 'test'</div>"
“测试”=>“基本测试”,
'test2'=>“在'test'之后进行的二次测试”

如果我收到您的问题,您希望在
中插入BASICTEST

$array=array(
“测试”=>“基本测试”,
“test2'=>”在“$array[“test”]”之后进行的二次测试;
);
echo$array['test2'];

$array['test2']=''$数组['test'].'
您期望的输出是什么?在完全创建数组之前,您无法寻址数组的内容。直到收盘时才会发生这种情况(代码>)
]已到达。您能为该代码添加一些解释吗?为什么你认为它解决了这个问题?请为代码片段添加一些上下文,以方便将来的读者。我不希望更改代码的结构。我想知道是否有另一种方法可以将它设置为变量,然后通过双引号或相关的方式再次输出。你所说的代码结构是什么意思?你没有发布任何代码我的意思是我的数组包括'test'和'test2'。在'test'的值内,我还想输出'test2'的值。类似于我的第二个代码行-它显然有语法错误,并且没有输出动态代码,而是输出一个文本。test2的预期输出是在基本测试之后进行的二次测试-我希望这能让我的问题更清楚,如果从一开始就不清楚,我很抱歉。有什么想法吗?
<?php   
function str_insert($str, $search, $insert) {
    $index = strpos($str, $search);
    if($index === false) {
        return $str;
    }
    return substr_replace($str, $search.$insert, $index, strlen($search));
}

$arr = array();
$arr = ["test" => "BASICTEST", "test2" => "<div id='secondary'>secondary test made after ''</div>"];
$str = $arr['test2'];
$add = $arr['test'];

$res = str_insert($str, "<div id='secondary'>secondary test made after '", $add);
$new_arr = array();
$new_arr = ["test" => "$add", "test2" => "$res"];
var_dump($new_arr);
$array = array(
    'test' => 'BASICTEST',
    'test2' => '<div id="secondary">secondary test made after '.$array["test"].'</div>';
);

echo $array['test2'];