I have a json of the form:
{
"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": []
}
}
}
}
I need to get a structured array from JSON, for that I have a function. What is the problem, I am confused by multiple checks and loops
private function getArray(array $items): array
{
$data = [];
foreach ($items as $key => $value) {
if (is_array($value)) {
array_push($data, $key);
foreach ($value as $items => $item) {
if (is_array($value)) {
array_push($data, $items, $item);
}
}
}
}
return $data;
}
Example output:
"Defendant",
2017,
[
"SolutionsPerv" => [
"To leave the decision unchanged, and the appeal - without satisfaction (paragraph 1 of article 269 of the APC)" => [
"Amount" => 10576596.8,
"Quantity" => 1
],
"Leave the decision (ruling) of the first instance court and the decision of the court of appeal unchanged, and the cassation appeal without satisfaction" => [
"Amount" => 3519672.72,
"Quantity" => 1
]
],
"DecisionsApp" => [
"To leave the decision unchanged, and the appeal - without satisfaction (paragraph 1 of article 269 of the APC)" => [
"Amount" => 10576596.8,
"Quantity" => 1
],
"Leave the decision (ruling) of the first instance court and the decision of the court of appeal unchanged, and the cassation appeal without satisfaction" => [
"Amount" => 3519672.72,
"Quantity" => 1
]
],
"ResheniyaKass" => [
"Leave the decision (ruling) of the first instance court and the decision of the court of appeal unchanged, and the cassation appeal without satisfaction" => [
"Amount" => 3519672.72,
"Quantity" => 1
]
],
"DecisionsNadz" => [
]
],
2021,
[
"SolutionsPerv" => [
"No solution" => [
"Amount" => 44014383.56,
"Quantity" => 1
]
],
"DecisionsApp" => [],
"ResheniyaKass" => [],
"DecisionsNadz" => []
]
How can you rewrite this function to simplify it, get rid of a few checks and loops, so that it is more compact?
Thanks in advance for your answer!
source https://stackoverflow.com/questions/67886065/how-to-rewrite-the-function-more-compact
No comments:
Post a Comment