PHP newbie

just starting to learn php
what is wrong with this code please ? nothing is echoed to the screen

<?php

function melon($arg1, $arg2, $arg3)
{

$result = ($arg1 + ($arg2 + $arg3));
return $result;
echo $result;

}

melon(3,3,4);

?>

ps is there any php guru on here who would volunteer to mark my (simple) php exercises ?

:slight_smile:

The reason why nothing is being echo’d is because you returned before you echo’d.

Try out this code:

<?php

function melon($arg1, $arg2, $arg3)
{

$result = ($arg1 + ($arg2 + $arg3));
echo $result;

}

melon(3,3,4);


?>

if you want to return through a function, try this code:

<?php 

function melon($arg1, $arg2, $arg3)
{

$result = ($arg1 + ($arg2 + $arg3));
return $result;

}

echo melon(3, 3, 4);

?>

many thanks!
can i come back to you re: arrays ?

$result = ($arg1 + ($arg2 + $arg3));

I don’t think there parantasis are really necessary. Try removing them all and see if it still produces the same result.

same result !