Skip to content

Instantly share code, notes, and snippets.

@smichaelsen
Last active July 14, 2016 07:54
Show Gist options
  • Save smichaelsen/7afac33fe90f4f14003e1e11246c4fdd to your computer and use it in GitHub Desktop.
Save smichaelsen/7afac33fe90f4f14003e1e11246c4fdd to your computer and use it in GitHub Desktop.
Nested foreach over ObjectStorage
array (size=4)
0 => string 'outer' (length=5)
1 => string 'inner' (length=5)
2 => string 'inner' (length=5)
3 => string 'inner' (length=5)
<?php
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
$testObjectStorage = new ObjectStorage();
$testObjectStorage->attach(new FrontendUser());
$testObjectStorage->attach(new FrontendUser());
$testObjectStorage->attach(new FrontendUser());
$executions = [];
foreach ($testObjectStorage as $feUser) {
$executions[] = 'outer';
foreach ($testObjectStorage as $feUser) {
$executions[] = 'inner';
}
}
var_dump($executions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment