Skip to content

Instantly share code, notes, and snippets.

Created April 2, 2013 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/5289621 to your computer and use it in GitHub Desktop.
Save anonymous/5289621 to your computer and use it in GitHub Desktop.
Group a section of elements in an array together.
$start_section = array();
$my_section = array();
$end_section = array();
$started = false;
foreach ($arr as $item) {
if (strpos($item, '?param=my_val') !== false) {
$my_section[] = $item;
$started = true;
} else {
if(!$started) {
$start_section[] = $item;
} else {
$end_section[] = $item;
}
}
}
$arr = array_merge($start_section, $my_section, $end_section);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment