Documentation

XmlNamedNodeList extends ReadonlyCollection
in package

XmlNamedNodeList

This class represents a list of nodes.

Table of Contents

Properties

$document  : DOMDocument
$data  : mixed
Collection internal data
$_document  : DOMDocument
The document.

Methods

__construct()  : mixed
Constructor
__get()  : mixed
Getter
__set()  : void
Magic method to set the value of a property by its name.
Add()  : mixed
Adds a key-value pair to the collection.
Append()  : void
Appends data from another source to the collection.
Clean()  : void
Clears empty values.
Clear()  : void
Clears the collection by removing all key-value pairs.
Contains()  : bool
Checks if the specified item exists in the data array.
Count()  : int
Returns the number of elements in the collection.
Delete()  : bool
Removes the key-value pair with the specified key from the collection.
DeleteAt()  : bool
Removes the key-value pair at the specified index from the collection.
Exists()  : bool
Checks if the key exists
Extract()  : Collection
Extracts data from a specified page using the given page size.
Filter()  : Collection
Filters the collection data based on the provided closure.
First()  : mixed|null
Retrieves the first element from the collection.
FromString()  : Collection
Creates a collection from a string representation.
getIterator()  : XmlNamedNodeListIterator
Returns an iterator for iteration using foreach.
IndexOf()  : mixed|null
Searches for the specified item in the data array and returns its index.
Insert()  : mixed
Inserts a key-value pair at the specified index in the data array.
Item()  : XmlNode|null
Returns the node by key.
ItemAt()  : XmlNode
Returns the node by index.
jsonSerialize()  : mixed
Serializes the object to a value that can be natively serialized by json_encode().
Key()  : string|null
Retrieves the key at the specified index in the data array.
Last()  : mixed|null
Retrieves the last element from the collection.
offsetExists()  : bool
Checks whether an offset exists.
offsetGet()  : mixed|null
Retrieves the element from the collection at the specified index.
offsetGet()  : XmlNode
offsetSet()  : void
Sets the value at the specified offset in the data array.
offsetUnset()  : void
Unsets the value at the specified index.
ToArray()  : array<string|int, mixed>
Converts the collection data to an array.
ToString()  : string
Converts the collection data to a string representation.

Properties

$data

Collection internal data

protected mixed $data = null

Methods

__construct()

Constructor

public __construct(DOMNodeList $nodelist, DOMDocument $dom) : mixed
Parameters
$nodelist : DOMNodeList

The node list.

$dom : DOMDocument

The document.

__get()

Getter

public __get(string $property) : mixed
Parameters
$property : string

The property.

__set()

Magic method to set the value of a property by its name.

public __set(string $key, mixed $value) : void
Parameters
$key : string

The name of the property to set.

$value : mixed

The value to assign to the property.

Add()

Adds a key-value pair to the collection.

public Add(string $key, mixed $value) : mixed
Parameters
$key : string

The key to add.

$value : mixed

The value associated with the key.

Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->Add('g', 10) collection goes to be ['a' => 1, 'b' => 2, 'c' => 3, 'g' => 10]
Return values
mixed

The updated collection data.

Append()

Appends data from another source to the collection.

public Append(mixed $from) : void
Parameters
$from : mixed

The data source to append.

Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->Append(['g' => 10, 'c' => 11]) collection goes to be ['a' => 1, 'b' => 2, 'c' => 3, 'g' => 10, 'c' => 11]

Clean()

Clears empty values.

public Clean() : void

Clear()

Clears the collection by removing all key-value pairs.

public Clear() : void
Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->Clear() collection goes to be []

Contains()

Checks if the specified item exists in the data array.

public Contains(mixed $item) : bool
Parameters
$item : mixed

The item to search for.

Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->Contains(1) returns true
$collection->Contains(10) returns false
Return values
bool

True if the item is found, false otherwise.

Count()

Returns the number of elements in the collection.

public Count() : int
Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->Count() returns 3
Return values
int

The count of elements in the collection.

Delete()

Removes the key-value pair with the specified key from the collection.

public Delete(string $key) : bool
Parameters
$key : string

The key to delete.

Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->Delete('b') collection goes to be ['a' => 1, 'c' => 3]
Return values
bool

True if the key was successfully deleted, false otherwise.

DeleteAt()

Removes the key-value pair at the specified index from the collection.

public DeleteAt(int $index) : bool
Parameters
$index : int

The index of the key-value pair to delete.

Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->DeleteAt(1) collection goes to be ['a' => 1, 'c' => 3]
Return values
bool

True if the key-value pair was successfully deleted, false otherwise.

Exists()

Checks if the key exists

public Exists(string $key) : bool
Parameters
$key : string
Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->Exists('a') returns true
$collection->Exists('g') returns false
Return values
bool

Extract()

Extracts data from a specified page using the given page size.

public Extract(mixed $page, mixed $pagesize) : Collection
Parameters
$page : mixed

The page to extract data from.

$pagesize : mixed

The size of the page.

Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->Extract(1, 2) returns ['a' => 1, 'b' => 2]
$collection->Extract(2, 2) returns ['c' => 3]
Return values
Collection

The extracted data collection.

Filter()

Filters the collection data based on the provided closure.

public Filter(Closure $closure) : Collection
Parameters
$closure : Closure

The closure used for filtering.

Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->Filter(fn($k,$v) => $k==='a' && $v===1) returns ['a' => 1]
Return values
Collection

The filtered collection.

First()

Retrieves the first element from the collection.

public First() : mixed|null
Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->First() returns 1
Return values
mixed|null

The first element if the collection is not empty, or null if empty.

FromString()

Creates a collection from a string representation.

public static FromString(string $string[, array<string|int, mixed>|null $splitters = null ]) : Collection
Parameters
$string : string

The string containing data to initialize the collection.

$splitters : array<string|int, mixed>|null = null

Optional array of splitters to parse the string data.

Tags
example
$collection = Collection::FromString('a=1&b=2&c=3', ['=','&']);
$collection is ['a' => 1, 'b' => 2, 'c' => 3]
Return values
Collection

The initialized collection.

IndexOf()

Searches for the specified item in the data array and returns its index.

public IndexOf(mixed $item) : mixed|null
Parameters
$item : mixed

The item to search for.

Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->IndexOf(1) returns 'a'
$collection->IndexOf(10) returns null
Return values
mixed|null

The index of the item if found, or null if not found.

Insert()

Inserts a key-value pair at the specified index in the data array.

public Insert(mixed $index, mixed $key, mixed $value) : mixed
Parameters
$index : mixed

The index where the key-value pair should be inserted.

$key : mixed

The key to insert.

$value : mixed

The value associated with the key.

Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->Insert(1, 'g', 10) collection goes to be ['a' => 1, 'g' => 10, 'b' => 2, 'c' => 3]
Return values
mixed

The updated collection data.

Item()

Returns the node by key.

public Item(string $key) : XmlNode|null
Parameters
$key : string

The key.

Return values
XmlNode|null

The node, or null if not found.

ItemAt()

Returns the node by index.

public ItemAt(int $index) : XmlNode
Parameters
$index : int

The index.

Return values
XmlNode

The node.

jsonSerialize()

Serializes the object to a value that can be natively serialized by json_encode().

public jsonSerialize() : mixed
Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->jsonSerialize() returns ['a' => 1, 'b' => 2, 'c' => 3]
Return values
mixed

The serialized data, which can be of any type other than a resource.

Key()

Retrieves the key at the specified index in the data array.

public Key(int $index) : string|null
Parameters
$index : int

The index of the key to retrieve.

Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->Key(1) returns 'b'
$collection->Key(10) returns null
Return values
string|null

The key if found, or null if the index is out of bounds.

Last()

Retrieves the last element from the collection.

public Last() : mixed|null
Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->Last() returns 3
Return values
mixed|null

The last element if the collection is not empty, or null if empty.

offsetExists()

Checks whether an offset exists.

public offsetExists(mixed $offset) : bool

This method is executed when using isset() or empty() on objects implementing the ArrayAccess interface.

Parameters
$offset : mixed

The offset (index) to check for existence.

Return values
bool

Returns true if the offset exists, and false otherwise.

offsetGet()

Retrieves the element from the collection at the specified index.

public offsetGet(mixed $offset) : mixed|null
Parameters
$offset : mixed
Return values
mixed|null

The collection element or null if the element is not found.

offsetSet()

Sets the value at the specified offset in the data array.

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed

The offset where the value should be set.

$value : mixed

The value to assign to the specified offset.

offsetUnset()

Unsets the value at the specified index.

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed

ToArray()

Converts the collection data to an array.

public ToArray() : array<string|int, mixed>
Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->ToArray() returns ['a' => 1, 'b' => 2, 'c' => 3]
Return values
array<string|int, mixed>

The array representation of the collection data.

ToString()

Converts the collection data to a string representation.

public ToString([array<string|int, mixed>|null $splitters = null ][, mixed|null $mapFunction = null ]) : string
Parameters
$splitters : array<string|int, mixed>|null = null

Optional array of splitters to join the data elements.

$mapFunction : mixed|null = null

Optional mapping function to apply to each data element.

Tags
example
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->ToString(['=', '&']) returns 'a=1&b=2&c=3'
$collection->ToString(['=', '&'], fn($k,$v) => $v*2) returns 'a=2&b=4&c=6'
Return values
string

The string representation of the collection data.


        
On this page

Search results