A multi-dimensional array arr and another array key [1, 2] are known. The first element in the key represents the first latitude of the arr array, and the second element represents the second latitude of arr, similarly, the number of key elements is unknown. how to obtain the pairs listed by the key corresponding to arr... A multi-dimensional array arr and another array key = [1, 2] are known. The first element in the key represents the first latitude of the arr array, and the second element represents the second latitude of arr, similarly, the number of key elements is unknown. how to obtain the values listed by the key corresponding to arr,
For example, if the above key is 1, 2], I will obtain the arr [1, how key = 1, 2, 4]. I want to obtain the arr [1 [4]...
Reply content:
A multi-dimensional array arr and another array key = [1, 2] are known. The first element in the key represents the first latitude of the arr array, and the second element represents the second latitude of arr, similarly, the number of key elements is unknown. how to obtain the values listed by the key corresponding to arr,
For example, if the above key is 1, 2], I will obtain the arr [1, how key = 1, 2, 4]. I want to obtain the arr [1 [4]...
"0", "children" => [["value" => "0-0",], ["value" => "0-1 ", "children" => [["value" => "0-1-0",], ["value" => "1 ", "children" => [["value" => "1-0", "children" => [["value" => "1-0-0 ", "children" => [["value" => "1-0-0-0 ", "children" => [],]; $ key = [0, 1]; function getValueByKey ($ arr, $ key) {$ index = array_shift ($ key); if (count ($ key) = 0) return $ arr [$ index]; return getValueByKey ($ arr [$ index] ['Children '], $ key);} // change the valuefunction setValueByKey (& $ arr, $ key, $ value) of the corresponding index) {$ index = array_shift ($ key); if (count ($ key) = 0) return $ arr [$ index] ['value'] = $ value; return setValueByKey ($ arr [$ index] ['Children '], $ key, $ value);} setValueByKey ($ arr, $ key, '123 '); // return the matched data group. then, let's look at what you want to fetch. The value is print_r (getValueByKey ($ arr, $ key) ['value']).