Skip to content

Instantly share code, notes, and snippets.

@useless-stuff
Last active February 19, 2016 16:17
Show Gist options
  • Save useless-stuff/c98f808544bd420b5195 to your computer and use it in GitHub Desktop.
Save useless-stuff/c98f808544bd420b5195 to your computer and use it in GitHub Desktop.
PHP - RecursiveRegexIterator
<?php
// RecursiveRegexIterator
$data = array(
array(
'EC2-CHOPIN01',
'EC2-CHOPIN02',
'EC2-CHOPIN03',
),
array(
'EC2-CHOPIN04',
'EC2-MOZART01',
'EC2-MOZART02',
),
array(
'EC2-BACH01',
'EC2-BACH02',
'EC2-CHOPIN05',
),
);
$iterator = new RecursiveRegexIterator(new RecursiveArrayIterator($data), "/(CHOPIN)/", RegexIterator::ALL_MATCHES);
foreach ($iterator->getInnerIterator() as $value) {
foreach ($iterator->getChildren() as $value) {
echo $value.PHP_EOL;
}
}
// Output:
/*
EC2-CHOPIN01
EC2-CHOPIN02
EC2-CHOPIN03
EC2-CHOPIN04
EC2-CHOPIN05
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment