3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "some text here [baz] and here [you|him|her|foo|bar|baz|foo|option|test] and even here [another]."; // Capture strings between brackets preg_match_all('~\[([^]]+)]~', $string, $matches); $groups = []; foreach ($matches[1] as $values) { // Explode them on pipe $groups[] = explode('|', $values); } print_r($groups);

preferences:
44.82 ms | 406 KiB | 5 Q