SaraNextGen.Com

Text Book Back Questions and Answers - Chapter 5 PHP Function and Array 12th Computer Applications Samacheer Kalvi Solutions - SaraNextGen [2024-2025]


Updated On May 15, 2024
By SaraNextGen

Samacheer Kalvi 12th Computer Applications Solutions Chapter 5 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:

  • 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

o User-defined Function

o Pre-defined or System or built-in Function, and

o 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[0][0].”:TamilMark:“.$student[0][1].”.Englishmark:“.$student[0][2].”<br>”;echo

student[l][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.

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[0]. “, ” . $$teacher_name[1] . ” and ” . $teacher_name[2]
?>

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”;
?>

Additional Questions and Answers

I. Choose the Best Answer

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

Question 2.
A Function is a type of
a) subroutine
b) procedure
c) Either a or b
d) None of these
Answer:
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
Answer:
(c) both a & b

Question 4.
How many classifications of functions are there?
(a) 2
(b) 3
(c) 4
(d) 5
Answer:
(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
Answer:
c) Multi-dimensional

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) 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
Answer:
(b) I-False, 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 sent 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 the 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, Multifunctional, Multidimensional
Answer:
Multifunctional

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 an array is when it is combined with the …………………………. statement.
(a) if
(b) while
(c) for
(d) for each
Answer:
(d) for each

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 Questions.

Question 1.
What is a parameterized function?
Answer:
PHP Parameterized functions are the functions with parameters or arguments.

Question 2.
Define Magic functions?
Answer:

1. A function in PHP that starts with an underscore ( ) is called a magic function.

2. The magic function is present inside the class.

III. Explain in Brief Answer

Question 1.
Write the rules for parameters.
Answer:

  • 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?
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 5.
Write the advantages of functions.
Answer:

  • Reducing duplication of code
  • Decomposing complex problems into simpler pieces
  • Improving the clarity of the code
  • Reuse of code
  • Information hiding

Also Read : Text-Book-Back-Questions-and-Answers-Chapter-6-PHP-Conditional-Statements-12th-Computer-Applications-Samacheer-Kalvi-Solutions

SaraNextGen