<?php
$s = ' 1 2 3 4 5 6 7 8 9 10 11 12 ';
$matches = array();
$exp = preg_split('#\s+#u', trim($s));
foreach($exp as $key => $piece){
if(isset($exp[$key - 1])) $matches[] = $exp[$key - 1].' '.$piece;
if(isset($exp[$key - 2])) $matches[] = $exp[$key - 2].' '.$exp[$key - 1].' '.$piece;
}
var_dump($matches);
?>