Skip to content

Commit f858c73

Browse files
committed
IHF: xml_to_array readme info added.
1 parent b712516 commit f858c73

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Provides Laravel-specific and pure PHP helper functions.
6161
- [str_lower](#str_lower)
6262
- [str_upper](#str_upper)
6363
64+
- [Xml](#xml)
65+
- [xml_to_array](#xml_to_array)
66+
6467
## Array
6568
6669
#### `array_except_value()`
@@ -285,3 +288,57 @@ $upper = str_upper('TeSt');
285288
286289
// TEST
287290
```
291+
292+
## Xml
293+
294+
#### `xml_to_array()`
295+
296+
Converts xml string to array:
297+
298+
```php
299+
$array = xml_to_array('<?xml version="1.0" encoding="UTF-8"?>
300+
<root>
301+
<tasks>
302+
<task>
303+
<to>John</to>
304+
<from>Jane</from>
305+
<title>Go to the shop</title>
306+
</task>
307+
<task>
308+
<to>John</to>
309+
<from>Paul</from>
310+
<title>Finish the report</title>
311+
</task>
312+
<task>
313+
<to>Jane</to>
314+
<from>Jeff</from>
315+
<title>Clean the house</title>
316+
</task>
317+
</tasks>
318+
</root>
319+
');
320+
321+
// [
322+
// 'tasks' => [
323+
// 'task' => [
324+
// 0 => [
325+
// 'to' => 'John',
326+
// 'from' => 'Jane',
327+
// 'title' => 'Go to the shop',
328+
// ],
329+
// 1 => [
330+
// 'to' => 'John',
331+
// 'from' => 'Paul',
332+
// 'title' => 'Finish the report',
333+
// ],
334+
// 2 => [
335+
// 'to' => 'Jane',
336+
// 'from' => 'Jeff',
337+
// 'title' => 'Clean the house',
338+
// ],
339+
// ],
340+
// ],
341+
// ];
342+
```
343+
344+
Alternatively, you can pass an instance of `SimpleXMLElement` object, to get the same results.

0 commit comments

Comments
 (0)