The following works:
echo "test {$var}";
This does not work:
echo "test {$var['value']}";
Is there a way to get that to work, without having to break up the string?
Maybe you need to remove $var from memory by unset($var) if you want use it again as an array not as a string.
$var = 'works';
echo "test {$var}";
//test works
unset($var);// if don't use this
//Fatal error will be thrown TypeError: Cannot access offset of type string on string
$var['value'] = 'also works';
echo "test {$var['value']}";
//test also works
You should be able to just do echo "test $var[value]".
This example worked perfectly for me:
$arr1 = array(
"foo" => "hello",
"bar" => "world"
);
echo "Test $arr1[foo]\n";
$arr2 = array("hello", "world");
echo "Test $arr2[1]\n";
// You can also use variables
$get1 = "foo";
$get2 = 1;
echo "Test $arr1[$get1]\n";
echo "Test $arr2[$get2]\n";
This ouputs:
Test hello
Test world
Test hello
Test world
Fatal error: Uncaught Error: Undefined constant "value" you need to wrap it by single-quotes!
$var['value'] = 'a val'; echo "test {$var['value']}";