CachingIterator::__toString

(PHP 5, PHP 7, PHP 8)

CachingIterator::__toString — Return the string representation of the current element

Beschreibung

public function CachingIterator::__toString(): string

Gets the string representation of the current element. What is returned depends on the flags of the CachingIterator:

CachingIterator::CALL_TOSTRING

The current element converted to a String. The conversion is done when the iterator moves to the element.

CachingIterator::TOSTRING_USE_KEY

The key of the current element converted to a String.

CachingIterator::TOSTRING_USE_CURRENT

The current element converted to a String. The conversion is done when this method is called.

CachingIterator::TOSTRING_USE_INNER

The inner iterator converted to a String. The conversion is done when the iterator moves to the element, before the inner iterator is moved forward.

Parameter-Liste

Diese Funktion besitzt keine Parameter.

Rückgabewerte

The string representation of the current element.

Beispiele

Beispiel #1 Using the keys as the string representation

<?php
$iterator = new CachingIterator(
    new ArrayIterator(['apple' => 3, 'banana' => 5]),
    CachingIterator::TOSTRING_USE_KEY
);

foreach ($iterator as $count) {
    echo $iterator, ': ', $count, "\n";
}
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

apple: 3
banana: 5

Siehe auch

User Contributed Notes

There are no user contributed notes for this page.
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top