3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{ "result":{ "Plaintiff":{ "2015":{ "SolutionsPerv":{ "To leave the decision (determination) of the court of first instance and the ruling of the court of appeal unchanged, and the cassation appeal - unsatisfied":{ "Amount":0, "Quantity":1 } }, "DecisionsApp":{ "To leave the decision (determination) of the court of first instance and the ruling of the court of appeal unchanged, and the cassation appeal - unsatisfied":{ "Amount":0, "Quantity":1 } }, "ResheniyaKass":{ "To leave the decision (determination) of the court of first instance and the ruling of the court of appeal unchanged, and the cassation appeal - unsatisfied":{ "Amount":0, "Quantity":1 } }, "ResheniyaNadz":[ ] } }, "Respondent":{ "2018":{ "SolutionsPerv":{ "Leave the ruling of the court of first instance and the ruling of the court of appeal unchanged, the cassation appeal without satisfaction":{ "Amount":24000, "Quantity":1 } }, "ResheniyaKass":{ "Leave the ruling of the court of first instance and the ruling of the court of appeal unchanged, the cassation appeal without satisfaction":{ "Amount":24000, "Quantity":1 } }, "ResheniyaNadz":[ ] }, "2019":{ "ResheniyaKass":{ "To leave the decision (determination) of the court of first instance and the ruling of the court of appeal unchanged, and the cassation appeal - unsatisfied":{ "Amount":0, "Quantity":1 } }, "ResheniyaNadz":[ ] }, "2020":{ "SolutionsPerv":{ "There is no decision":{ "Amount":0, "Quantity":2 } }, "DecisionsApp":[ ] } }, "Third Person":{ "2015":{ "SolutionsPerv":{ "To leave unchanged the decision and (or) the decision of the appellate instance, and the cassation appeal - without satisfaction (clause 1 of part 1 of article 287 of the APC)":{ "Amount":0, "Quantity":1 } }, "ResheniyaNadz":[ ] } } } }'; $debug = true; $arr = json_decode($json, true); $result = getArray($arr, 'Respondent'); // use e.g. Plaintiff or Respondent as $id print_r($result); function getArray(array $arr = [], string $id = '', &$store = []): array { foreach ($arr as $key => $value) { if ($key === $id && is_array($value)) { // identifier found return $store = $value; // store result array } elseif (is_array($value)) getArray($value, $id, $store); // keep digging } return $store; }

preferences:
24.63 ms | 405 KiB | 5 Q