fork download
  1. <?php
  2.  
  3. $names = array('SMITH JOHN', 'BACON KEVIN', 'MERCURY FREDDIE');
  4. $names = preg_replace('/^(\S+)\s+(\S+)$/', '\2 \1', $names);
  5.  
  6. var_dump($names);
  7.  
  8. ?>
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
array(3) {
  [0]=>
  string(10) "JOHN SMITH"
  [1]=>
  string(11) "KEVIN BACON"
  [2]=>
  string(15) "FREDDIE MERCURY"
}