• Welcome to your new Gnomio site

    Now, you are in control!

    Moodle is an open-source Learning Management System (LMS) that provides educators with the tools and features to create and manage online courses. It allows educators to organize course materials, create quizzes and assignments, host discussion forums, and track student progress. Moodle is highly flexible and can be customized to meet the specific needs of different institutions and learning environments.

    Moodle supports both synchronous and asynchronous learning environments, enabling educators to host live webinars, video conferences, and chat sessions, as well as providing a variety of tools that support self-paced learning, including videos, interactive quizzes, and discussion forums. The platform also integrates with other tools and systems, such as Google Apps and plagiarism detection software, to provide a seamless learning experience.

    Moodle is widely used in educational institutions, including universities, K-12 schools, and corporate training programs. It is well-suited to online and blended learning environments and distance education programs. Additionally, Moodle's accessibility features make it a popular choice for learners with disabilities, ensuring that courses are inclusive and accessible to all learners.

    The Moodle community is an active group of users, developers, and educators who contribute to the platform's development and improvement. The community provides support, resources, and documentation for users, as well as a forum for sharing ideas and best practices. Moodle releases regular updates and improvements, ensuring that the platform remains up-to-date with the latest technologies and best practices.

    Links of interest:

    (You can edit or remove this text)

Available courses

UNIT-3:FUNCTIONS

GFGC, SHIMOGA Page 1

PHP Functions: It is a piece of code that can be reused many times. It can take input as

argument list and return value. There are thousands of built-in functions in PHP.

 In PHP, we can define Conditional function, Function within Function and Recursive

function also.

Advantage of PHP Functions

Code Reusability: PHP functions are defined only once and can be invoked many times, like

in other programming languages.

Less Code: It saves a lot of code because you don't need to write the logic many times. By the

use of function, you can write the logic only once and reuse it.

Easy to understand: PHP functions separate the programming logic. So it is easier to

understand the flow of the application because every logic is divided in the form of functions.

PHP provides us with two major types of functions:

1. Built-in functions : PHP provides us with huge collection of built-in library functions.

 These functions are already coded and stored in form of functions. To use those we just

 need to call them as per our requirement like, var_dump, fopen(), print_r(), gettype() and

 so on.

2. User Defined Functions : Apart from the built-in functions, PHP allows us to create our

 own customised functions called the user-defined functions. Using this we can create our

 own packages of code and use it wherever necessary by simply calling it.

Creating a Function

• While creating a user defined function we need to keep few things in mind:

• Any name ending with an open and closed parenthesis is a function.

• A function name always begins with the keyword function.

• To call a function we just need to write its name followed by the parenthesis

• A function name cannot start with a number. It can start with an alphabet or

underscore.

• A function name is not case-sensitive.

Syntax: function functionname(){

 //code to be executed

 }

Example:

function sayHello(){

echo "Hello PHP Function";

}

Call a Function: To call the function, just write its name followed by parentheses egg

<?php

function sayHello(){

echo "Hello PHP Function";

}

sayHello();//calling function

Output: Hello PHP Function

In our example, we create a function named sayHello().

The opening curly brace { indicates the beginning of the function code, and the closing curly

brace } indicates the end of the function.

The function outputs Hello PHP Function

PHP Function Arguments: We can pass the information in PHP function through arguments

which is separated by comma.

 PHP supports Call by Value (default), Call by Reference, Default argument

values and Variable-length argument list.

Syntax:

function function_name($first_parameter, $second_parameter) {

//executable code

}

Example

<?php

// function along with three parameters

function fun($num1, $num2, $num3)

{

 $product = $num1 * $num2 * $num3;

 echo "The product is $product";

}

// Calling the function

// Passing three arguments

fun(2, 3, 5);

?>

Output: The product is 30

Setting Default Values for Function parameter: PHP allows us to set default argument

values for function parameters. If we do not pass any argument for a parameter with default

value then PHP will use the default set value for this parameter in the function call.

Example:

<?php

 //function with default parameter

function fun($str, $num=12)

{

 echo "$str is $num years old\n”;

}

// Calling the function

fun(“Ram”,15);

// In this call, the default value 12 will be considered

fun(“Adam”);

?>

Output:

Ram is 15 years old

Adam is 12 years old