As of the end of each section in the PHP array to select an item and bring it?

Good afternoon. You have a page 93.90.220.244/get/treolan_cataloglist.php with the withdrawal of the array of the directory structure:
- Section [category]
 - The ordinal number of the partition in the array [0...n]
 - Subsection with its attendant attributes [category]
 If there are more subsections, the structure is repeated
...
 In the final subsection shows the goods to [position]
 - Pataday room tovar in the array [0...n]
 - Attributes [@attributes]
...
 The article attributes [articul]
 ...

e2735756d8.png
If you look in the mountains, you can see each of course...podpad-section [category] has a section [position]
a74b0f64cd.png
This block in the array [postiton], which are the elements podpad...section the [category] and which has the attributes [@attributes] that have a [articul].

Task - run the loop around the array with all elements of the [position] display [articul] list.
How can I do that?

Here is the code of the page with the output of the array:
the <pre>
<?php
ini_set("memory_limit", "1024M");

 $soapClientParams = array('connection_timeout' => 300);
 $soapClient = new
SoapClient("***",
$soapClientParams);
 try {
 $param = array(
 'Login' => '***',
 'password' => '***',
 'category' => ",
 'vendorid' => 0,
 'keywords' => ",
 'criterion' => 0,
 'inArticul' => 0,
 'inName' => 0,
 'inMark' => 0,
 'ShowNc' => 0);
 $info = $soapClient->__call("GenCatalogV2", $param);
 $arResult = ($info['Result']);

$xml = simplexml_load_string($arResult);
$json = json_encode($xml);
$xmlArr = json_decode($json, true);

print_r($xmlArr);

/*foreach ($xmlArr['category'] as $i => $section) {
 foreach ($section['category'] as $i => $subsection) {
 foreach ($subsection['category'] as $i => $subsubsection) {
print_r($subsubsection);
}
}
}*/

}
catch (SoapFault $fault) {
 print("Sorry, WS returned the following ERROR:
".$fault->faultcode."-".$fault->faultstring);
}
?>
March 20th 20 at 11:45
1 answer
March 20th 20 at 11:47
Solution
recursion
it can be an example for my problem? - Sammy.Ha commented on March 20th 20 at 11:50
I tried to use recursion. Code:
function recarray($ar, $searchfor) {
 static $result = array();

 foreach($ar as $k => $v) {
 if ($k == $searchfor) $result[] = $v;
 if (is_array($ar[$k])) recarray($v, $searchfor);
}
 return $result;
}

$result = recarray($xmlArr, 'articul');

print_r($result);


There is a problem - hatched the entire array or outside of it in some places, this array associative list with the articles. The screen shot below:
ee8903bad9.png
How to remove all the excess and leave only the list of item numbers? - Sammy.Ha commented on March 20th 20 at 11:53
@allen86,
function catalog($arr) {
 foreach ($arr as $key => $value) {
 echo $value.'\n';
catalog($value);
}
}

Figuratively like this) - Evelyn.Litt commented on March 20th 20 at 11:56
@John.Strac, do Not understand how your code work! I have using code:
function recarray($ar, $searchfor) {
 static $result = array();

 foreach($ar as $k => $v) {
 if ($k == $searchfor) $result[] = $v;
 if (is_array($ar[$k])) recarray($v, $searchfor);
}
 return $result;
}

$result = recarray($xmlArr, 'articul'); // $xmlArr array catalogue

print_r($result);

To obtain this result (a list of items in a PHP array):
tMKjCUc.png - Sammy.Ha commented on March 20th 20 at 11:59
@John.Strac, it is Possible an example? - Sammy.Ha commented on March 20th 20 at 12:02
@allen86, from the phone wrote a primitive)
And the fact that above, I do not understand the origin... on screen not found... - Evelyn.Litt commented on March 20th 20 at 12:05
@allen86, i.e. before 22125 where the values are? - Evelyn.Litt commented on March 20th 20 at 12:08
@John.Strac, it's parts all there from 1 to the n-th number of the articles are, in the screenshot I have shown only a part, but the strange along with articles displays the sections where this article is - Sammy.Ha commented on March 20th 20 at 12:11
@allen86, and, as I understand 22125 left, the rest of the rules? - Evelyn.Litt commented on March 20th 20 at 12:14
@John.Strac, too, but most importantly a disgrace to what is left of the original array 8d5a4f593f.png - Sammy.Ha commented on March 20th 20 at 12:17
@allen86, Attention
The reference to $value in the last element of the array will remain after the end of the foreach loop. It is recommended to destroy it using unset(). Otherwise, you may face this behaviour:....

I think here the dog rummaged - Evelyn.Litt commented on March 20th 20 at 12:20
@John.Strac, it Turns out I in this code:
function recarray($ar, $searchfor) {
 static $result = array();

 foreach($ar as $k => $v) {
 if ($k == $searchfor) $result[] = $v;
 if (is_array($ar[$k])) recarray($v, $searchfor);
}
 return $result;
}

$result = recarray($xmlArr, 'articul');

print_r($result);

Need to return $result; insert unset($return); ??? - Sammy.Ha commented on March 20th 20 at 12:23
@allen86, no, unset($v); not at the end, you have the same recursion, i.e., in a cycle the cycle starts and it already needs to be destroyed $v... as I understand it, something like that...

Maybe more intelligent people are better to tell, I'm just learning) - Evelyn.Litt commented on March 20th 20 at 12:26
@John.Strac, it worked, it turns out in my recursive code should have been replaced if ($k == $searchfor) if ($k === $searchfor)
5T091TgkIyQ.jpg - Sammy.Ha commented on March 20th 20 at 12:29
@allen86, was this idea, but for some reason thought it too))) probably because never when comparing strings I have had this problem to once and the data type match... - Evelyn.Litt commented on March 20th 20 at 12:32
@John.Strac, well, damn it, because of the missing EQUAL sign flew all the code( that's all of the cons of programming... - Sammy.Ha commented on March 20th 20 at 12:35
@allen86, but such complications then the memory hits well) I also will consider the future) - Evelyn.Litt commented on March 20th 20 at 12:38

Find more questions by tags PHPArrays