function parentPush($array, $key , $parent = null){
$result = [];
foreach ($array as $k => $v) {
if(isset($v[$key])){
if ($parent)
$v[$key]['code_parent'] = $parent;
$result[] = array_diff_key($v[$key], array_flip(['category']));
}
if (isset($v["code"]))
$parent = $v["code"];
$m = is_array($v)? parentPush($v, $key, $parent) : null;
$result = is_array($v)? array_merge_recursive($result, $m) : $result;
}
return $result;
}
function parentPush($array, $key , $parent = null){
$result = [];
foreach ($array as $k => $v) {
if(isset($v[$key])){
if ($parent)
$v[$key]['code_parent'] = $parent;
$result[] = array_diff_key($v[$key], array_flip(['category']));
}
if (isset($v["code"]))
$parent = $v["code"];
$m = is_array($v)? parentPush($v, $key, $parent) : null;
$result = is_array($v)? array_merge_recursive($m, $result) : $result;
}
return $result;
}
function parentPush($array, $key , $parent = null){
$result = [];
foreach ($array as $k => $v) {
if(isset($v[$key])){
if ($parent)
$v[$key]['code_parent'] = $parent;
$result[] = [$key => array_diff_key($v[$key], array_flip(['category']))];
}
if (isset($v["code"]))
$parent = $v["code"];
$m = is_array($v)? parentPush($v, $key, $parent) : null;
$result = is_array($v)? array_merge_recursive($m, $result) : $result;
}
return $result;
}
function recarray($ar, $searchfor, $parent = null)
{
$result = [];
$code_parent = null;
foreach ($ar as $k => $v) {
if ($k === $searchfor) {
if ($parent)
$v['code_parent'] = $parent;
if (isset($v["code"]))
$code_parent = $v["code"];
$result[$k] = is_array($v)? recarray($v, $searchfor, $code_parent): $v;
} else {
$result[$k] = is_array($v)? recarray($v, $searchfor, $parent): $v;
}
}
return $result;
}
Array
(
[0] => Array
(
[@attributes] => Array
(
[code] => 1251
[name] => Красота и здоровье
[category] => Array
(
[0] => Array
(
[@attributes] => Array
(
[code] => BAC
[name] => Фен счтетки
[code_parent] => 1251
)
)
[1] => Array
(
[@attributes] => Array
(
[code] => EPI
[name] => Эпиляторы
[code_parent] => 1251
)
)
[2] => Array
(
[@attributes] => Array
(
[code] => HCL
[name] => Машинки для стрижки
[code_parent] => 1251
)
)
)
)
)
[1] => Array
(
[@attributes] => Array
(
[code] => 1253
[name] => Красота и здоровье
[category] => Array
(
[0] => Array
(
[@attributes] => Array
(
[code] => BAC
[name] => Фен счтетки
[code_parent] => 1253
)
)
[1] => Array
(
[@attributes] => Array
(
[code] => EPI
[name] => Эпиляторы
[code_parent] => 1253
)
)
[2] => Array
(
[@attributes] => Array
(
[code] => HCL
[name] => Машинки для стрижки
[code_parent] => 1253
)
)
)
)
)
)
Только вот мне не понятно от куда взялся метод calcRequest ?
Документацию про SoapClient читал так и не могу там понять ничего
// здесь твоя ветвистая структура запроса
$data = [
"keyAsArray" => [
"key1" => "value",
"key2" => "value",
"key3" => "и так далее"
]
];
// Всякого рода опции, вплоть до передачи логина и пароля, работы с ssl и т.д.
$params = [
"trace" => 1
];
$soapClient = new SoapClient('https://ufot.rgs.ru/Osago2Service.svc?singlewsdl', $params);
$result = $soapClient->calcRequest($data);
print_r($result);
function recarray($ar, $searchfor, $parent = null)
{
$result = [];
$code_parent = null;
foreach ($ar as $k => $v) {
if ($k === $searchfor) {
if ($parent)
$result['code_parent'] = $parent;
if (isset($v["code"]))
$code_parent = $v["code"];
$result[$k] = is_array($v)? recarray($v, $searchfor, $code_parent): $v;
} else {
$result[$k] = is_array($v)? recarray($v, $searchfor, $parent): $v;
}
}
return $result;
}
$categories = [
[
"@attributes" => [
"code" => 1251,
"name" => "Красота и здоровье",
"category" => [
[
"@attributes" => [
"code" => "BAC",
"name" => "Фен счтетки",
]
],
[
"@attributes" => [
"code" => "EPI",
"name" => "Эпиляторы"
],
],
[
"@attributes" => [
"code" => "HCL",
"name" => "Машинки для стрижки"
],
],
]
]
],
[
"@attributes" => [
"code" => 1253,
"name" => "Красота и здоровье",
"category" => [
[
"@attributes" => [
"code" => "BAC",
"name" => "Фен счтетки",
]
],
[
"@attributes" => [
"code" => "EPI",
"name" => "Эпиляторы"
],
],
[
"@attributes" => [
"code" => "HCL",
"name" => "Машинки для стрижки"
],
],
]
]
]
];
print_r(recarray($categories, "@attributes"));
Array
(
[0] => Array
(
[@attributes] => Array
(
[code] => 1251
[name] => Красота и здоровье
[category] => Array
(
[0] => Array
(
[code_parent] => 1251
[@attributes] => Array
(
[code] => BAC
[name] => Фен счтетки
)
)
[1] => Array
(
[code_parent] => 1251
[@attributes] => Array
(
[code] => EPI
[name] => Эпиляторы
)
)
[2] => Array
(
[code_parent] => 1251
[@attributes] => Array
(
[code] => HCL
[name] => Машинки для стрижки
)
)
)
)
)
[1] => Array
(
[@attributes] => Array
(
[code] => 1253
[name] => Красота и здоровье
[category] => Array
(
[0] => Array
(
[code_parent] => 1253
[@attributes] => Array
(
[code] => BAC
[name] => Фен счтетки
)
)
[1] => Array
(
[code_parent] => 1253
[@attributes] => Array
(
[code] => EPI
[name] => Эпиляторы
)
)
[2] => Array
(
[code_parent] => 1253
[@attributes] => Array
(
[code] => HCL
[name] => Машинки для стрижки
)
)
)
)
)
)
function recarray($ar, $searchfor, $parent = null)
{
$result = [];
$code_parent = null;
foreach ($ar as $k => $v) {
if ($k === $searchfor) {
if ($parent)
$result['code_parent'] = $parent;
if (isset($v["code"]))
$code_parent = $v["code"];
$result[$k] = is_array($v)? recarray($v, $searchfor, $code_parent): $v;
} else {
$result[$k] = is_array($v)? recarray($v, $searchfor, $parent): $v;
}
}
return $result;
}
Уже устарел. Не поддерживается.