我正在尝试循环数据库例程,但是我在使获取数组包含变量时遇到问题。
${"db" . $currentTime . "11"} = ${"data" . $currentTime . "1"}[${$currentTLower . "11"}];
$currentTime
包含'A'
$currentTLower
包含'a'
因此代码行如下所示:
$dbA11 = $dataA1[a11];
但是,它没有成功。
答案 0 :(得分:1)
你非常接近。索引应为“a11”,但不应与代码
中的$a11
相同
$currentTime = 'A';
$currentTLower ='a';
$dataA1['a11'] = 'value';
${"db" . $currentTime . "11"} = ${"data" . $currentTime . "1"}[$currentTLower . "11"];
echo $dbA11; // value
答案 1 :(得分:0)
<?php
$currentTime = "A";
$currentTLower = "A1";
$A111 = "Test";
$dataA1[$A111] = "This is content";
${"db".$currentTime."11"} = ${"data".$currentTime . "1"}[${$currentTLower . "11"}];
echo ${"db".$currentTime."11"};
// IT will print : This is content
?>