【发布时间】:2019-10-19 10:04:23
【问题描述】:
即使它已记录在案,我也需要帮助以更好地理解此代码(仅参考)。我已经检查了教程,但它们没有帮助我。
// initialize variables
$val = 'it works !';
$arr = [];
// Get the keys we want to assign
$keys = [ 'key_1', 'key_2', 'key_3', 'key_4' ];
// Get a reference to where we start
$curr = &$arr;
// Loops over keys
foreach($keys as $key) {
// get the reference for this key
$curr = &$curr[$key];
}
// Assign the value to our last reference
$curr = $val;
// visualize the output, so we know its right
var_dump($arr);
echo "<hr><pre>\$arr : "; print_r($arr);
(来源:https://stackoverflow.com/a/31103901/4741362@Derokorian)
【问题讨论】:
标签: php arrays multidimensional-array associative