Tamilnadu State Board New Syllabus Samacheer Kalvi 12th Computer Applications Guide Pdf Chapter 5 PHP Function and Array Text Book Back Questions and Answers, Notes.

## Tamilnadu Samacheer Kalvi 12th Computer Applications Solutions Chapter 5 PHP Function and Array

### 12th Computer Applications Guide PHP Function and Array Text Book Questions and Answers

Part I

Question 1.
Which one of the following is the right way of defining a function in PHP?
a) function { function body }
b) data type functionName(parameters) { function body }
c) functionName(parameters) { function body }
d) function functionName(parameters) { function body }
d) function functionName(parameters) { function body }

Question 2.
A function in PHP which starts with (double underscore) is known as ……………
a) Magic Function
b) Inbuilt Function
c) Default Function
d) User Defined Function
a) Magic Function

Question 3.
PHP’s numerically indexed array begins with position …………….
a) 1
b) 2
c) 0
d) -1
c) 0

Question 4.
Which of the following are correct ways of creating an array?
ii) $state[] = array(“Tamilnadu”); iii)$state[0] = “Tamilnadu”;
iv) $state = array(“Tamilnadu”); a) iii) and iv) b) ii) and iii) c) Only i) d) ii), iii) and iv) Answer: d) ii), iii) and iv) Question 5. What will be the output of the following PHP code? <?php$a=a rray (“A”,”Cat”,”Dog “,”A”,”Dog “);
$b=a rray C’A” “A” “Cat”,”A”,”Tiger”);$c=array_combine($a,$b);
print__r(array_count_va!ues($c)); ?> a) Array ([A] => 5 [Cat] = > 2 [Dog] => 2 [Tiger] = >1) b) Array ([A] => 2 [Cat] => 2 [Dog] => 1 [Tiger] = > 1) c) Array ( [A] => 6 [Cat] => 1 [Dog] -> 2 [Tiger] = > 1) d) Array ([A] => 2 [Cat] => 1 [Dog] => 4 [Tiger] = > 1) e) None of these Answer: e) None of these Question 6. For finding nonempty elements in array we use a) is„array () function b) sizeof () function c) array_count () function d) count () function Answer: b) sizeof () function Question 7. Indices of arrays can be either strings or numbers and they are denoted as a)$my_array {4}
b) $my_array [4] c)$my_array | 4 |
d) None of them
d) None of them

Question 8.
PHP arrays are also called as
a) Vector arrays
b) Perl arrays
c) Hashes
d) All of them
a) Vector arrays

Question 9.
As compared to associative arrays vector arrays are much
a) Faster
b) Slower
c) Stable
d) None of them
b) Slower

Question 10.
What functions count elements in an array?
a) count
b) Sizeof
c) Array_Count
d) Count_array
a) count

Part II

Question 1.
Define Function in PHP.
In most of the programming language, a block of the segment in a program that performs specific operation tasks (Insert, Execute, Delete, Calculate, etc.). This segment is also known as Function. A Function is a type of subroutine or procedure in a program.

Question 2.
Define User define Function.

• User-Defined Function (UDF) in PHP gives a privilege to the user to write their own specific: operation inside of existing program module.
• A user-defined function declaration begins with the keyword “function”.
• Users can write any custom logic inside the function block.

Question 3.
What is parameterized Function?
Parameterized Function:

1. PHP Parameterized functions are the functions with parameters or arguments.
2. Required information can be shared between function declaration and function calling part inside the program.
3. The parameter is also called as arguments, it is like variables.
4. The arguments are mentioned after the function name and inside of the parenthesis.
5. There is no limit for sending arguments, just separate them with a comma notation.

Question 4.
List out System defined Functions.

• is_bool() function -By using this function, we can check whether the variable is a boolean variable or not.
• is_int() function 3y using this function, we can check the input variable is an integer or not.
• is_float() function-By using this function, we can check the float variable is an integer or not.
• is_null() function-By using the is_null function, we can check whether the variable is NULL or not.

Question 5.
Write Syntax of the Function in PHP.
SYNTAX:
function functionName()
{
Custom Logic code to be executed;
}

Question 6.
Define Array in PHP.
Array is a concept that stores more than one value of the same data type (homogeneous) in the single array variable. They are 3 types of array in PHP.

1. Indexed Arrays
2. Associative Array and
3. Multi-Dimensional Array

Question 7.
Usage of Array in PHP.
The array() function is used to create an array.
In PHP, there are three types of arrays:

• Indexed arrays – Arrays with a numeric index
• Associative arrays – Arrays with named keys
• Multidimensional arrays – Arrays containing one or more arrays

Question 8.
List out the types of the array in PHP.
They are 3 types of array concepts in PHP.

1. Indexed Arrays,
2. Associative Array and
3. Multi-Dimensional Array.

Question 9.
Define associative array.
Associative arrays are a key-value pair data structure. Instead of having storing data in a linear array, with associative arrays you can store your data in a collection and assign it a unique key which you may use for referencing your data.

Question 10.
Write array Syntax in PHP.
array(key=>value,key=>value,key=> value,etc.); key = Specifies the key (numeric or string value – Specifies the value)

Part III

Question 1.
Write the features System define Functions.
System Defined Functions: A function is already created by system it is a reusable piece or block of code that performs a specific action. Functions can either return values when called or can simply perform an operation without returning any value.

Features of System defined functions:

1. System defined functions are otherwise called as predefined or built-in functions.
2. PHP has over 700 built in functions that performs different tasks.
3. Built in functions are functions that exists in PHP installation package.

Question 2.
Write the purpose of parameterized Function.

• Information can be passed to functions through arguments.
• An argument is just like a variable.
• Arguments are specified after the function name, inside the parentheses. We can add as many arguments as you want, just separate them with a comma.

Question 3.
Differentiate user define and system define Functions.

 User-defined Functions. System define Functions User-Defined Functions are the functions which are created by user as per his own requirements. System define Functions are Predefined functions. In User Defined Functions, name of function can be changed any time In System Defined Functions, Name of function can’t be changed In User Defined Functions, the name of function id de­cided by user In System Defined Functions, it is giv­en by developers.

Question 4.
Write Short notes on Array.
Array is a concept that stores more than one value of same data type (homogeneous) in single array variable. They are 3 types of array concepts in PHP.

1. Indexed Arrays,
2. Associative Array and
3. Multi-Dimensional Array.

Question 5.
Differentiate Associate array and Multidimensional array.

 Associate array Multidimensional array Associative arrays are arrays that use named keys that you assign to them. Array containing one or more arrays. It storing data in a linear Multidimensional arrays that are two, three, four, five, or more levels deep. We can associate name with each array elements in PHP using => symbol. It can be represented in the form of a matrix which is represented by row * column.

Part IV

Explain in detail

Question 1.
Explain Function concepts in PHP.
Functions in PHP
In most the programming language, a block of segments in a program that performs specific operation tasks (Insert, Execute, Delete, Calculate, etc.). This segment is also known as Function. A Function is a type of subroutine or procedure in a program.

Function will be executed by a call to the Function and the Function returns any data type values or NULL value to called Function in the part of the respective program.
The Function can be divided into three types as follows:

1. User-defined Function,
2. Pre-defined or System or built-in Function, and
3. Parameterized Function.

1. User-Defined Function:
User-Defined Function (UDF) in PHP gives a privilege to the user to write own specific operation inside of existing program module. Two important steps the Programmer has to create for users to define Functions are Function declaration and Function calling.

2. System Define Functions:
A function is already created by system it is a reusable piece or block of code that performs a specific action. Functions can either return values when called or can simply perform an operation without returning any value.

3. Parameterized Function:
PHP Parameterized functions are the functions with parameters or arguments.

Question 2.
Discuss in detail User-defined Functions.

• User-Defined Function (UDF) in PHP givesa privilege to user to write own specific operation inside of existing program module.
• Two important steps the Programmer has to cre-ate for users define Functions are:

Function Declaration

• A user-defined Function declaration begins with the keyword “function”.
• User can write any custom logic inside the function block.

Syntax:
function functionName()
{
Custom Logic code to be executed;
}

Function Calling:

• A function declaration part will be executed by a ! call to the function.
• Programmer has to create Function Calling part j inside the respective program.

Syntax:
functionName();

Example:
<?php
function insertMsg() {
echo “Student Details Inserted Successfully!”;
}
insertMsg(); // call the function
?>

Question 3.
Explain the Multidimensional Array.
Multidimensional Arrays:

1. A multidimensional array is an array containing one or more arrays.
2. PHP understands multidimensional arrays that are two, three, four, five, or more levels deep.
3. However, arrays more than three levels deep are hard to manage for most people.

Example:
<?php
// A two-dimensional array Sstudent-array
(
array(“Iniyan”, 100,96),
array(“Kavin”,60,59),
array(“Nilani”,1313,139)
);
echo $$student[0][0].“: Tamil Mark: “.student [0][1]English mark: “.student [0] [2].”<br>”; echo$$student[1][0].“: Tamil Mark: “.$student [1][1].”. English mark: “.$student [1] [2].”<br>”;

echo $$student[2][0].“: Tamil Mark: “.student [2][1]English mark: “.student [2] [2].”<br>”; ?> Question 4. Explain Array concepts and their types. Answer: Array is a concept that stores more than one value of same data type (homogeneous) insingle array variable. They are 3 types of array con¬cepts in PHP. 1. Indexed Arrays, 2. Associative Array and 3. Multi-Dimensional Array. Indexed Arrays Arrays with numeric index for the available values in array variable which contains keyvalue pair as user / developer can take the values using keys. Associative Arrays • Associative arrays are a key-value pair data structure. • Instead of having storing data in alinear array, with associative arrays you can store your data in a collection and assign it aunique key which you may use for referencing your data. Multidimensional Arrays • A multidimensional array is an array containing one or more arrays. • PHP understands multidimensional arrays that are two, three, four, five, or more levels deep. • However, arrays more than three levels deep are hard to manage for most people. Question 5. Explain Indexed array and Associatearray in PHP. Answer: Indexed Arrays: Arrays with numeric index for the available values in array variable which contains key value pair as user / developer can take the values using keys. Example: <?php teacher_name=array(“Iniyan”, “Kavin”, “Nilani”); echo “The students name are “ . teacher_name[0]. “, “ .$$teacher_name[l]. “ and” . $teacher_name[2]. ?> Associative Arrays: 1. Associative arrays are a key-value pair data structure. 2. Instead of having storing data in a, linear array, with associative arrays you can store your data. Example: <?php$Marks=array(“Student1”=>“35”,“Student2”==>“17”,“Student3”=>“43”);
echo “Student1 mark is” . $Marks[‘Student1’]. “ is eligible for qualification”; echo “Student2 mark is” .$Marks[‘Student2’]. “ is not eligible for qualification”;

### 12th Computer Applications Guide Introduction to Hypertext Pre-Processor Additional Important Questions and Answers

Part A

Question 1.
A block of the segment in a program that performs specific operation tasks is known as
a) Arrays
b) Segments
c) Functions
d) All of these
c) Functions

Question 2.
PHP has over ………………………. built-in functions.
(a) 200
(b) 500
(c) 700
(d) 900
(c) 700

Question 3.
is a concept that stores more than one value of the same data type in a single array variable,
a) Arrays
b) Segments
c) Functions
d) All of these
a) Arrays

Question 4.
………………….. arrays are a key-value pair data structure.
a) Associative
b) Indexed
c) Multi-dimensional
d) All of these
b) Indexed

Question 5.
Find the wrong statement from the following?
(a) pre-defined functions are called built-in functions
(b) pre-defined functions are called system functions
(c) parameterized functions are called system functions
(c) parameterized functions are called system functions

Fill in the blanks:

1. PHP has over …………. functions built-in that perform different tasks.
700

2. PHP functions are dived into …………. types.
three

3. A user-defined Function declaration begins with the keyword ………….
function

4. The parameter is also called………….
arguments

5. Array defines with the keyword ………….
array()

SYNTAX

1. Function Declaration:
function functionName()
{
Custom Logic code to be executed;
}

2. Function Calling:
functionName();

3. Indexed Arrays:
$Array_Variable = array( “valuel”, “value2″”value2”); 4. Associative Arrays array(key=>value,key=>value,key=>- value,etc.); Choose the incorrect statements; 1. a) PHP Functions are Reducing duplication of code b) PHP Functions are Decomposing complex problems into simpler pieces c) PHP Functions are Improving the clarity of the code d) PHP Functions are collections of variables. Answer: d) PHP Functions are collections of variables. 2. a) PHP Functions are Reuse of code b) PHP Functions are Information hiding c) PHP Parameterized functions are the functions without parameters d) PHP arrays are using For each looping concepts Answer: c) PHP Parameterized functions are the functions without parameters 3. a) Array is a collection of heterogeneous data b) An Array is a block of code that performs a specific action. c) A function is already created by the system it is a reusable piece d) An array is a special variable, which can hold more than one value at a time. Answer: b) An Array is a block of code that performs a specific action. Question 4. a) An array is a block of statements that can be used repeatedly in a program. b) The index can be assigned automatically in a collection of the data set c) A multidimensional array is an array containing one or more arrays. d) Associative arrays are arrays that use named keys that you assign to them. Answer: a) An array is a block of statements that can be used repeatedly in a program. 5. a) User Defined Function (UDF) in PHP gives a privilege to the user to write own specific operation inside of existing program module. b) A user-defined Function declaration begins with the keyword “function”. c) A Function is a type of subroutine or procedure in a program. d) A Function will not be executed by a call to the Function Answer: d) A Function will not be executed by a call to the Function Match the following: 1. Indexed Arrays – System function 2. Associative Arrays – Function with arguments 3. Multidimensional Arrays – Key value pair 4. Parameterized function – Array containing one or more array 5. Predefined function – Numeric Index Answer: 1. Numeric Index 2. Key valued pair 3. Array containing one or more array 4. Function with arguments 5. System Function Very Short Answers Question 1. Classify functions? Answer: The Function can be divided into three types as follow: 1. User-defined Function 2. Pre-defined or System or built-in Function, and 3. Parameterized Function. Question 2. What is an associative array? Answer: Associative arrays are arrays that use named keys that you assign to them. Question 3. How index will be assigned in an indexed array? Answer: The index can be assigned automatically in a collection of the data set Question 4. What is a Multi-Dimensional Array? Answer: A multidimensional array is an array containing one or more arrays. Part B Short Answers Question 1. Write a PHP program for function with one arguments? Answer: <?php function School_Name($sname) {
}
SchoolName (“Government Higher Secondary School Madurai”);
SchoolName (“Government Higher Secondary School Trichy”);
School Name (“Government Higher Secondary School Chennai”);
School Name (“Government Higher Secondary School Kanchipuram”);
School Name (“Government Higher Secondary School Tirunelveli”);
?>

Question 2.
Give important characteristics of PHP functions?