(PHP 5 >= 5.2.0, PHP 7, PHP 8)
RegexIterator::setFlags — 設定旗標
flags
要設定的旗標,一個類別常數的位元遮罩。
可用的旗標列於下方。這些旗標的實際意義在預定義常數中描述。
值 | 常數 |
---|---|
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