[Solved] Why ‘return’ is used in PHP , Codeigniter to retrive or insert data to database?


From the php manual:

If called from within a function, the return statement immediately ends execution of the current function, and returns its argument as the value of the function call

http://php.net/manual/en/function.return.php

That means the “return” statement will return the data to the parent method who called it.

The behavior of DB operations will depend on the frameworks/libraries you are using.

From the codeigniter manual:

insert([$table=""[, $set = NULL[, $escape = NULL]]])
RETURNS: TRUE on success, FALSE on failure

https://www.codeigniter.com/userguide3/database/query_builder.html

When selecting, the “return” statement will return the row from the database or “false” if not found.

solved Why ‘return’ is used in PHP , Codeigniter to retrive or insert data to database?