3v4l.org

run code in 300+ PHP versions simultaneously
<?php function splitname($input) { $input = trim($input); if ( strlen($input) < 1 ) return array( 0 => null, 1 => null ); $input = explode(' ', $input); if ( count($input) < 2 ) return array( 0 => $input[0], 1 => null ); $lastname = end($input); unset($input[count($input) - 1]); $firstname = implode(' ', $input); return array( 0 => $firstname, 1 => $lastname ); } echo var_dump(splitname(' aasd fef')); ?>

preferences:
36.44 ms | 402 KiB | 5 Q