【发布时间】:2018-03-01 06:56:11
【问题描述】:
我想通过点分隔键删除特定的子数组。这里有一些工作(是的,它工作但甚至不是一个好的解决方案)代码:
$Data = [
'one',
'two',
'three' => [
'four' => [
'five' => 'six', // <- I want to remove this one
'seven' => [
'eight' => 'nine'
]
]
]
];
# My key
$key = 'three.four.five';
$keys = explode('.', $key);
$str = "";
foreach ($keys as $k) {
$sq = "'";
if (is_numeric($k)) {
$sq = "";
}
$str .= "[" . $sq . $k . $sq . "]";
}
$cmd = "unset(\$Data{$str});";
eval($cmd); // <- i'd like to get rid of this evil shit
对此有更好的解决方案的任何想法?
【问题讨论】: