$array_names=array("phone","car","house");
我有以下字符串: $phone_[$jr]
但是带有被称为phone的字符串的字符串是值的名称,我想使用其他名称来获取值,这样就需要这样写:
${$phone}
问题是我需要在此字符串中使用其他内容:
${$phone}_[$jr]
这给了我错误
我看到问题在于“ _”,但我需要使用,我的问题是关于我需要如何正确地写出作品
$ {$ phone} _ [$ jr]
在其他情况下,我需要使用:
${$house}_[$jr]
等等.....
谢谢
答案 0 :(得分:0)
我假设您有这样的情况:
// this is the array you are trying to access dynamically
$bar_ = [];
// this will hold the first part of the variable name
$phone = 'bar';
// and this is how you would build the string which is the full name of the array
// You can then use it to access one of its elements.
${$phone.'_'}[1] = 'f';