CakeFest 2024: The Official CakePHP Conference

RegexIterator::setFlags

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

RegexIterator::setFlagsフラグを設定する

説明

public RegexIterator::setFlags(int $flags): void

フラグを設定します。

パラメータ

flags

設定するフラグ。クラス定数のビットマスクで指定します。

利用できるフラグは次のとおりです。これらのフラグの実際の意味については 定義済みの定数 で説明します。

RegexIterator のフラグ
定数
1 RegexIterator::USE_KEY

戻り値

値を返しません。

例1 RegexIterator::setFlags() の例

新しい RegexIterator を作成します。これは、キーが 'test' ではじまるすべてのエントリを取り出します。

<?php
$test
= array ('str1' => 'test 1', 'teststr2' => 'another test', 'str3' => 'test 123');

$arrayIterator = new ArrayIterator($test);
$regexIterator = new RegexIterator($arrayIterator, '/^test/');
$regexIterator->setFlags(RegexIterator::USE_KEY);

foreach (
$regexIterator as $key => $value) {
echo
$key . ' => ' . $value . "\n";
}
?>

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

teststr2 => another test

参考

add a note

User Contributed Notes

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