« Dom\TokenList::getIterator
Dom\TokenList::remove »

Dom\TokenList::item

(PHP 8 >= 8.4.0)

Dom\TokenList::item — リストからトークンを返す

説明

public function Dom\TokenList::item(int $index): ?string

リストの index に存在するトークンを返します。

パラメータ

index

トークンのインデックス

戻り値

index に存在するトークンを返します。 インデックスが範囲外の場合は null を返します。

例

例1 Dom\TokenList::item() の例

有効なインデックスと無効なインデックスにアクセスします

<?php
$dom = Dom\HTMLDocument::createFromString('<p class="font-bold important"></p>', LIBXML_NOERROR);
$p = $dom->body->firstChild;

$classList = $p->classList;
var_dump(
    $classList->item(0),
    $classList->item(100),
);
?>

上の例の出力は以下となります。

string(9) "font-bold"
NULL

注意

注意:

このメソッドは、配列にアクセスする記法を使うことと同等です。

関連キーワード:
TokenList   トークン   item   index   インデックス   classList   font   bold   getIterator   remove   範囲   無効   HTMLDocument   createFromString   important   body   firstChild   dump   記法
関連する関数・ページ:
dom-tokenlist.add   dom-tokenlist.remove   dom-tokenlist.contains   dom-tokenlist.count   dom-tokenlist.replace   class.dom-tokenlist