Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Xml.php
Go to the documentation of this file.
1 <?php
7 
11 class Xml
12 {
20  public function xmlToAssoc(\SimpleXMLElement $xml)
21  {
22  $array = [];
23  foreach ($xml as $key => $value) {
24  if (isset($value->{$key})) {
25  $i = 0;
26  foreach ($value->{$key} as $v) {
27  $array[$key][$i++] = (string)$v;
28  }
29  } else {
30  // try to transform it into string value, trimming spaces between elements
31  $array[$key] = trim((string)$value);
32  if (empty($array[$key]) && !empty($value)) {
33  $array[$key] = $this->xmlToAssoc($value);
34  } else {
35  // untrim strings values
36  $array[$key] = (string)$value;
37  }
38  }
39  }
40  return $array;
41  }
42 }
$value
Definition: gender.phtml:16
xmlToAssoc(\SimpleXMLElement $xml)
Definition: Xml.php:20
$i
Definition: gallery.phtml:31