Dom\TokenList::item

(PHP 8 >= 8.4.0)

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

説明

public 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

注意

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

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top