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

Students can Download Computer Applications Chapter 5 PHP Function and Array Questions and Answers, Notes Pdf, Samacheer Kalvi 12th Computer Applications Book Solutions Guide Pdf helps you to revise the complete Tamilnadu State Board New Syllabus and score more marks in your examinations.

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

### Samacheer Kalvi 12th Computer Applications PHP Function and Array Text Book Back Questions and Answers

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 begin 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[ ] = arfay(“Tamilnadu”); (iii)$state = “Tamilnadu”;
(iv) $state = array(“Tamilnadu”); (a) (iii) and (iv) (b) (ii) and (iii) (c) Only (i) (d) (ii), (iii) and (iv) Answer: (a) (iii) and (iv) Question 5. What will be the output of the following PHP code? <?php$a=array(“A”,“Cat”,“Dog”,“A”,“Dog”);
$b=array(“A”,“A”,“Cat”,“A”,“Tiger”);$c=array_combine($a,$b);
print_r(array_count_values($c)); ?> (а) 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) Answer: (а) Array ([A] => 5 [Cat] => 2 [Dog] => 2 [Tiger] => 1) 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: (d) count ( ) function Question 7. Indices of arrays can be either strings or numbers and they are denoted as (a)$my_array {4}
(b) $my array  (c)$my_array |4|
(d) None of these
(b) $my array Question 8. PHP arrays are also called as (a) Vector arrays (b) Perl arrays (c) Hashes Answer: (c) Hashes Question 9. As compared to associative arrays, vector arrays are much (a) Faster (b) Slower (c) Stable (d) None of them Answer: (b) Slower Question 10. What functions count elements in an array? (a) count (b) both a and b (c) Array Count (d) Count_array Answer: (b) both a and b PART – II I. Short Answer Question 1. Define Function in PHP? Answer: • A Function is a type of subroutine or procedure in a program. • A 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. Question 2. Define User-defined Function? Answer: User-Defined Function: User-Defined Function (UDF) in PHP gives a privilege to the user to write their own specific operation inside of existing program module. Function Declaration: A user-defined function declaration begins with the keyword “function”. Question 3. What is parameterized Function? Answer: • PHP Parameterized functions are the functions with parameters or arguments. • The arguments are mentioned after the function name and inside of the parenthesis. Question 4. List out System defined Functions? Answer: 1. round 2. cos 3. tan 4. is_number 5. rand etc 6. sqrt 7. sin 8. pi 9. number_format Question 5. Define Array in PHP? Answer: • The array is a data type which has multiple values in a single variable. • In other words, Array is a concept that stores more than one value of the same data type (homogeneous) in the single array variable. Question 7. Usage of Array in PHP? Answer: One of the most useful aspects of using arrays in PHP is when combined with the foreach statement. This allows you to quickly loop though an array with very little code. Question 8. List out the types of arrays in PHP? Answer: Question 9. Define associative array? Answer: • 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? Answer: Array defines with the keyword array( ) PART – III III. Explain in Brief Answer Question 1. Write the features of System defined Functions? Answer: • A function is a block of statements that can be used repeatedly in a program. • A function will not execute immediately when a page loads. • A function will be executed by a call to the function. Question 2. Write the purpose of parameterized Function? Answer: 1. Required information can be shared between function declaration and function calling part inside the program. 2. The parameter is also called as arguments, it is like variables. The arguments are mentioned after the function name and inside of the parenthesis. 3. There is no limit for sending arguments, just separate them with a comma notation. Question 3. Differentiate user define and system-defined Functions? Answer: System defined: 1. These functions are already present in the system (comes along with installation package). 2. Cannot be edited. 3. Name is provided by the developer Eg. isnum( ), isalpha( ). System defined: 1. These functions are already present in the system (comes along with installation package). 2. Cannot be edited. 3. Name is provided by the developer Eg. isnum( ), isalpha( ). Question 4. Write Short notes on Array? Array in PHP Answer: 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 concepts in PHP. 1. Indexed Arrays, 2. Associative Array and 3. Multi-Dimensional Array. Syntax: 1. array(key= > value, key=>value, key=> value, etc.); 2. key = Specifies the key (numeric or string) 3. value = Specifies the value Question 5. Differentiate Associate array and Multidimensional array? Answer: Associate 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. Multidimensional array: 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. PART – IV IV. Explain in detail Question 1. Explain Function concepts in PHP? Answer: • A block of segments in a program that performs specific operation tasks is also known as Function. • A Function is a type of subroutine or procedure in a program. • A 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 • User-defined Function • Pre-defined or System or built-in Function, and • Parameterized Function. User-defined Function User to write own specific operation inside of existing program module. Pre-defined or System or built-in Function, A function is already created by the system it is a reusable piece or block of code that performs a specific action. Parameterized Function. PHP Parameterized functions are the functions with parameters or arguments Question 2. Discuss in detail User-defined Functions? Answer: User-Defined Function: 1. User can create their own functions. 2. User-Defined Function (UDF) in PHP gives a privilege to user to write own specific operation inside of existing program module. 3. Two important steps the Programmer has to create for users define Functions are: Function Declaration: A user-defined function declaration begins with the keyword “function”. Users 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 inside the respective program. Syntax: functionName( ); Example: <?php function insertMsg( ) { echo “Student Details Inserted Successfully!”; } insertMsg( ); // call the function ?> Parameterized Function: 1. Required information can be shared between function declaration and function calling part inside the program. 2. The parameter is also called as arguments, it is like variables. 3. The arguments are mentioned after the function name and inside of the parenthesis. There is no limit for sending arguments, just separate them with a comma notation. Question 3. Explain the Multidimensional Array? Answer: Multidimensional Arrays • A multidimensional array is an array containing j one or more arrays. • PHP understands multidimensional arrays that j are two, three, four, five, or more levels deep. | • However, arrays more than three levels deep are hard to manage for most people. Example: <?php // A two-dimensional array$student=array(array(“Iniyan”,100,96),array(“Kavin”60,59),array(“Nilani”,1313,139)); echo $$student.”: Tamil Mark: “.student .”. English mark: “.student  .”<br>”; echo$$student[l].”: Tamil Mark: “$.student .”. English mark: “.$student  .”<br>”;
echo $$student.”: Tamil Mark: “.student .”. English mark: “.student  .”<br>”; ?> Question 4. Explain Array concepts and their types? Answer: Arrays in PHP: 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. SYNTAX: Array Syntax: Array defines with the keyword array( ) 1. 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. 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 in a collection and assign it a unique key which you may use for referencing your data. Question 3. Multidimensional Arrays? Answer: 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. Question 5. Explain Indexed array and Associate array in PHP? Answer: Indexed Arrays; Arrays with numeric index for the available values in array variable which contains key value pairas user / developer can take the values using keys. Example: <?php teacher_name=array(“Iniyan”, “Kavin”, “Nilani”); echo “The students name are ” . teacher_ name. “, ” .$$teacher_name . ” and ” . $teacher_name ?> 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. Example: <?php$Marks = array(“Studentl”->”35″,”Stu-
dent2″=>”17″”Student3″=>”43″);
echo “Studentl mark is” . $Marks[‘Studentl’] . ” is eligible for qualification”; echo “Student2 mark is” .$Marks[‘Student2’] .
” is not eligible for qualification”;
?>

### Samacheer Kalvi 12th Computer Applications Solutions PHP Function and Array Additional Questions and Answers

Question 1.
………………………. are functions that exist in the PHP installation package.
Built-in functions

Question 2.
A Function is a type of
a) subroutine
b) procedure
c) Either a or b
d) None of these
c) Either a or b Question 3.
A function is a type of …………………………… in a program.
(a) subroutine
(b) procedure
(c) both a & b
(d) array
(c) both a & b

Question 4.
How many classifications of functions are there?
(a) 2
(b) 3
(c) 4
(d) 5
(b) 3 Question 5.
A ………………… array is an array containing one
or more arrays.
a) Associative
b) Indexed
c) Multi-dimensional
d) All of these
c) Multi-dimensional

Question 6.
UDF stands for …………………………..
User-defined functions Question 7.
Pick the odd one out related to functions.
(a) userdefined
(b) pre-defined
(c) system
(d) builtin
(a) user-defined

Question 8.
Find the statement which is correct.
I: A user-defined function declaration begins with the keyword “user”
II: user can write any custom logic inside the function block
(a) I-True, II-False
(b) I-False, II-True
(c) I, II-True
(d) I, II-False
(b) I-False, II-True Question 9.
The parameter is also called as
(a) Arguments
(b) Value
(c) Calling function
(d) return
(a) Arguments

Question 10.
THe arguments are separated by
(a) .
(b) :
(c) ,
(d) ;
(c) , Question 11.
The arguments have to be enclosed within
(a) [ ]
(b) <>
(c) { }
(d) ( )
(d) ( )

Question 12.
The function blocks are given by
(a) [ ]
(b) <>
(c) { }
(d) ( )
(c) { }

Question 13.
How many arguments can be sent to return a value in a function?
(a) 2
(b) 3
(c) 4
(d) No limit
(d) No limit Question 14.
Which statement can be used to return a value in a function?
(a) pass
(b) call
(c) return
(d) give
(c) return

Question 15.
Which is used to store more than one value in a single variable of the same data type?
(a) Array
(b) Functions
(c) Class
(d) Object
(a) Array Question 16.
How many types of arrays are there?
(a) 1
(b) 2
(c) 3
(d) 4
(c) 3

Question 17.
Pick the odd one out.
Indexed, Associative, Multifunctional, Multidimensional
Multifunctional Question 18.
What is the keyword for creating an array?
(a) Arr( )
(b) array( )
(c) a( )
(d) a[ ]
(b) array( )

Question 19.
One of the most useful aspects of using an array is when it is combined with the …………………………. statement.
(a) if
(b) while
(c) for
(d) for each
(d) for each Question 20.
…………………………. specifies the value in the syntax of Association Array.
(a) value
(b) Val
(c) value at
(d) value of
(a) value

Question 21.
The key in the Associative Array may be of …………………………… or …………………………..
numeric or string

Question 22.
………………………… arrays are a key-value pair data structure.
(a) Indexed
(b) Numeric
(c) Associative
(d) Multidimensional
(c) Associative Question 23.
In PHP ………………………….. are Information hiding.
(a) Functions
(b) Variables
(c) Keywords
(d) datatypes
(a) Functions

Question 1.
What is a parameterized function?
PHP Parameterized functions are the functions with parameters or arguments. Question 2.
Define Magic functions?

1. A function in PHP that starts with an underscore ( ) is called a magic function.
2. The magic function is present inside the class.

Question 1.
Write the rules for parameters.

• PHP Parameterized functions are the functions with parameters or arguments.
• The parameter is also called as arguments, it is like variables.

Rules:

• The arguments are mentioned after the function name and inside of the parenthesis.
• There is no limit to sending arguments, just separate them with a comma notation. Question 2.
Give an example for function with two arguments?
<?php
function School_Name($sname,$Stfength) {
echo $sname.“in Tamilnadu and Student Strength is”.$Strength;
}
School Name (“Government Higher Secondary School Madurai”,200);
School Name (“Government Higher Secondary School Trichy”,300);
School Name (“Government Higher Secondary School Chennai”,250);
School Name (“Government Higher Secondary School Kanchipuram”, 100);
School Name (“Government Higher Secondary School Tirunelveli”,200);
?>

Question 3.
Write a PHP program to explain function with return values?
For a function to return a value, use the return statement
<?php
function sum($x,$y) {
$z =$x + $y; return$z;
}
echo “5 + 10 = “ . sum(5, 10). “<br>”;
echo “7 + 13 = “ . sum(7, 13). “<br>”;
echo “2 + 4 = “ . sum(2, 4);
?> Question 4.
Give the Syntax for Associative Arrays?
Associative Arrays Syntax:
array(key ⇒ value,key ⇒ value,key ⇒ value,etc.);
key = Specifies the key (numeric or string)
value = Specifies the value.

Question 5.
What is the use of array combine( ) in PHP?
The array_combine( ) is an inbuilt function in PHP.
It is used to combine two arrays and create a new array by using one array for keys and another for values.
Eg. $c = array_combine($a, \$b); IV. Explain in detail

Question 5.