PHP递归获取二维数组中指定key的值
$data = [ "resulterrorCode" => 0, "resultraw" => [ "result" => "ok", "trace_id" => "Xdm00694540804871731h0", "code" => 0, "data" => [ "id" => "tdm006945408048717384T", ], "description" => "成功", "info" => "Received push messages for 1 TOPIC" ], ]; echo "<pre>"; var_dump($data); function getDeepValue($array, $keys, $delimiter = '.') { $keys = explode($delimiter, $keys); $key = array_shift($keys); if (sizeof($keys) > 0 && isset($array[$key])) { return get_deep_value($array[$key], implode($delimiter, $keys), $delimiter); } else { return $array[$key] ?? null; } } $res = getDeepValue($data,'resultraw.data.id'); var_dump($res);