Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused about return statement in user defined function

i have few question regarding the return statement.

a) is it compulsory to define a return statement in a user defined function.?

b) is it still valid if i just define a return statement without any parameter? will it return the null value?

c) is the following function valid?

function admin_credential($password = 0, $email = 0) {
     if( $password != 0) {
         $password = sha1($password);
         $query = "UPDATE admins SET password = '$password'";
         $result = mysql_query($query);
         }
     if( $email != 0) {
         $query = "UPDATE admins SET email = '$email'";
         $result = mysql_query($query);            
         }
         return;
         }
like image 887
Ibrahim Azhar Armar Avatar asked Feb 27 '23 06:02

Ibrahim Azhar Armar


1 Answers

a) is it compulsory to define a return statement in a user defined function.?

No.

b) is it still valid if i just define a return statement without any parameter? will it return the null value?

Yes.

c) is the following function valid?

Yes, but $result will be lost because you are not returning it. The return is not really necessary.

like image 110
Pekka Avatar answered Mar 05 '23 13:03

Pekka