我想通過點分隔鍵刪除特定的子陣列。下面是一些工作(是它的工作,但甚至還沒有接近一個很好的解決方案)代碼:通過點分隔鍵刪除多維數組中的子樹
$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
對這個更漂亮的解決方案的任何想法?
謝謝,這工作得很好:) – Link