madoreo madoreo - 7 months ago 121
PHP Question

PHP getName function

I am trying to write a function that accepts a first and last name as arguments and then returns the full name, and then tests the solution by making a call.

I have this code and I am not sure if it captures these points or not as I am fairly new to PHP. Can anyone let me know if this code captures this or am I going wrong?

function getName($first, $second){
$FullName = $first . $second;
echo $FullName;
getName('Lil', ' Wayne');

Answer Source

Your code is already working, however, you can use this!


function name($first, $second)

    if ($first !== NULL && $second !== NULL) {

        $fullname = $first . $second;

        return $fullname;

    } else {

        return "Names are missing!";


  echo name('Lil', ' Wayne');


Good luck!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download