How To Fix Return Type Of A Function

Share Now

***Fix the return type of a function in order to avoid errors.

<?php

//INT TYPE
function sum(int $x, int $y, int $z):int {
    return $x+$y+$z;
}
echo sum(5,5,5);

//STRING TYPE
function txt( string $fname, string $lname):string {
    return $fname.' '.$lname;
}
 echo txt('Sherlock','Holmes');?>
Picture of Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert