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
I. Choose The Correct Answer
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 }
Answer:
(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
Answer:
(a) Magic Function
Question 3.
PHP’s numerically indexed array begin with position ………………………..
(a) 1
(b) 2
(c) 0
(d) -1
Answer:
(c) 0
Question 4.
Which of the following are correct ways of creating an array?
(i) state[0] = “Tamilnadu”;
(ii) $state[ ] = arfay(“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:
(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 [4]
(c) $my_array |4|
(d) None of these
Answer:
(b) $my array [4]
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:
In most of the programming language, a block of segment in a program that performs a specific operation tasks (Insert, Execute, Delete, Calculate, etc.). This segment is also known as Function. A Function is a type of sub routine or procedure in a program.
Question 2.
Define User defined Function?
Answer:
User Defined Function:
User Defined Function (UDF) in PHP gives a privilege to user to write 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:
Parameterized Function:
- PHP Parameterized functions are the functions with parameters or arguments.
- Required information can be shared between function declaration and function calling part inside the program.
- The parameter is also called as arguments, it is like variables.
- 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 4.
List out System defined Functions?
Answer:
- round
- cos
- tan
- is_number
- rand etc
- sqrt
- sin
- pi
- number_format
Question 5.
Define Array in PHP?
Answer:
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 in PHP.
- Indexed Arrays
- Associative Array and
- Multi-Dimensional Array
‘
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 array 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:
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:
- System defined functions are otherwise called as predefined or built-in functions.
- PHP has over 700 built in functions that performs different tasks.
- Built in functions are functions that exists in PHP installation package.
Question 2.
Write the purpose of parameterized Function?
Answer:
- Required information can be shared between function declaration and function calling part inside the program.
- The parameter is also called as arguments, it is like variables. 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.
Differentiate user define and system defined Functions?
Answer:
System defined:
- These functions are already present in the system (comes along with installation package).
- Cannot be edited.
- Name is provided by the developer Eg. isnum( ), isalpha( ).
System defined:
- These functions are already present in the system (comes along with installation package).
- Cannot be edited.
- 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 same data type (homogeneous) in single array variable. They are 3 types of array concepts in PHP.
- Indexed Arrays,
- Associative Array and
- Multi-Dimensional Array.
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:
Functions in PHP
In most of the programming language, a block of segment in a program that performs a specific operation tasks (Insert, Execute, Delete, Calculate, etc.). This segment is also known as Function. A Function is a type of sub routine 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 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.
1. User Defined Function:
User Defined Function (UDF) in PHP gives a privilege to user to write own specific operation inside of existing program module. Two important steps the Programmer has to create for users 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 about User defined Functions?
Answer:
User Defined Function:
- User can create their own functions.
- User Defined Function (UDF) in PHP gives a privilege to user to write own specific operation inside of existing program module.
- 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”. 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 inside the respective program.
Syntax:
functionName( );
Example:
<?php
function insertMsg( )
{
echo “Student Details Inserted Successfully!”;
}
insertMsg( ); // call the function
?>
Parameterized Function:
- Required information can be shared between function declaration and function calling part inside the program.
- The parameter is also called as arguments, it is like variables.
- 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 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.
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:
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.
- Indexed Arrays,
- Associative Array and
- 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:
- 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 3.
Multidimensional Arrays?
Answer:
- 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 Associate array 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:
- 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.
Example:
<?php
$Marks=array(“Studentl”=>“35”,“Student2”==>“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
I. Choose the Best Answer
Question 1.
………………………. are functions that exist in PHP installation package.
Answer:
Built-in functions
Question 2.
PHP has over ………………………. built in functions.
(a) 200
(b) 500
(c) 700
(d) 900
Answer:
(c) 700
Question 3.
A function is a type of …………………………… in a program.
(a) sub routine
(b) procedure
(c) both a & b
(d) array
Answer:
(c) both a & b
Question 4.
How many classification of functions are there?
(a) 2
(b) 3
(c) 4
(d) 5
Answer:
(b) 3
Question 5.
Find the wrong statement from the following?
(a) pre-defined functions are called as built-in functions
(b) pre-defined functions are called as system functions
(c) parameterized functions are called system functions
Answer:
(c) parameterized functions are called system functions
Question 6.
UDF stands for …………………………..
Answer:
User defined functions
Question 7.
Pick the odd one out related to functions.
(a) userdefined
(b) pre-defined
(c) system
(d) builtin
Answer:
(a) userdefined
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-Flase, II-True
(c) I, II-True
(d) I, II-False
Answer:
(b) I-Flase, II-True
Question 9.
The parameter is also called as
(a) Arguments
(b) Value
(c) Calling function
(d) return
Answer:
(a) Arguments
Question 10.
THe arguments are separated by
(a) .
(b) :
(c) ,
(d) ;
Answer:
(c) ,
Question 11.
The arguments have to be enclosed within
(a) [ ]
(b) <>
(c) { }
(d) ( )
Answer:
(d) ( )
Question 12.
The function blocks are given by
(a) [ ]
(b) <>
(c) { }
(d) ( )
Answer:
(c) { }
Question 13.
How many arguments can be send to return a value in a function?
(a) 2
(b) 3
(c) 4
(d) No limit
Answer:
(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
Answer:
(c) return
Question 15.
Which is used to store more than one value in a single variable of same data type?
(a) Array
(b) Functions
(c) Class
(d) Object
Answer:
(a) Array
Question 16.
How many types of arrays are there?
(a) 1
(b) 2
(c) 3
(d) 4
Answer:
(c) 3
Question 17.
Pick the odd one out.
Indexed, Associative, Multi functional, Multi dimensional
Answer:
Multi functional
Question 18.
What is the keyword for creating an array?
(a) Arr( )
(b) array( )
(c) a( )
(d) a[ ]
Answer:
(b) array( )
Question 19.
One of the most useful aspects of using array is when it is combined with the …………………………. statement.
(a) if
(b) while
(c) for
(d) foreach
Answer:
(d) foreach
Question 20.
…………………………. specifies the value in the syntax of Association Array.
(a) value
(b) val
(c) value at
(d) value of
Answer:
(a) value
Question 21.
The key in the Associative Array may be of …………………………… or …………………………..
Answer:
numeric or string
Question 22.
………………………… arrays are a key value pair data structure.
(a) Indexed
(b) Numeric
(c) Associative
(d) Multidimensional
Answer:
(c) Associative
Question 23.
In PHP ………………………….. are Information hiding.
(a) Functions
(b) Variables
(c) Keywords
(d) datatypes
Answer:
(a) Functions
II. Short Answer
Question 1.
Classify functions?
Answer:
The Function can be divided in to three types as follow
- User defined Function,
- Pre-defined or System or built-in Function, and
- Parameterized Function.
Question 2.
Define Magic functions?
Answer:
- A function in PHP which starts with underscore ( ) is called as magic function.
- Magic function is present inside the class.
III. Explain in Brief Answer
Question 1.
Write a PHP program for function with one arguments?
Answer:
<?php
function School_Name($sname) {
echo $sname.“in Tamilnadu.<br>”;
}
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 an example for function with two arguments?
Answer:
<?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?
Answer:
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?
Answer:
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?
Answer:
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 1.
Give important characteristics of PHP functions?
Answer:
- PHP Functions are Reducing duplication of code.
- PHP Functions are Decomposing complex problems into simpler pieces.
- PHP Functions are Improving clarity of the code.
- PHP Functions are Reuse of code.
- PHP Functions are Information hiding.