PHP code example of d-shorkin / arrayable-xml

1. Go to this page and download the library: Download d-shorkin/arrayable-xml library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

d-shorkin / arrayable-xml example snippets


$xmlString = <<<XML
<root rootAttr="bar">
    <example testAttr="foo">1</example>
    <example>2</example>
</root>
XML;

$factory = new Dshorkin\ArrayableXml\ArrayableXmlFactory();
$arrayableXml = $factory->create($xmlString);

var_dump($arrayableXml->toArray());

'providers' => [
    // ...
    
    Dshorkin\ArrayableXml\Laravel\ArrayableXmlProvider::class,
],

'aliases' => [
    // ...
    
    'ArrayableXml' => Dshorkin\\ArrayableXml\Laravel\ArrayableXml::class
]

ArrayableXml::create($xmlString)->toArray()

array(2) {
  ["rootAttr"]=>
  string(3) "bar"
  ["children"]=>
  array(1) {
    ["example"]=>
    array(2) {
      [0]=>
      array(2) {
        ["testAttr"]=>
        string(3) "foo"
        ["text"]=>
        string(1) "1"
      }
      [1]=>
      array(1) {
        ["text"]=>
        string(1) "2"
      }
    }
  }
}