3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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')); ?>
Output for 4.3.0 - 7.1.0
array(2) { [0]=> string(4) "aasd" [1]=> string(3) "fef" }