How To Fix Return Type Of A Function

Share Now

Share on facebook
Share on pinterest
Share on twitter
Share on linkedin
Share on email

***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');?>
Nahid Mahamud

Nahid Mahamud

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