PHP Function and Array
2 MARKS:
1. 1. WHAT IS FUNCTION?
A Function is a type of sub routine 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 respective program.
2. 2. GIVE SOME TYPES OF FUNCTION?
User defined Function,
Pre-defined or System or built-in Function
Parameterized Function.
3. 3. WHAT IS 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 in PHP.
● Indexed Arrays,
● Associative Array and
● Multi-Dimensional Array.
===============================
3 MARKS:
1. 1. WHAT IS INDEXED ARRAY?
Indexed Arrays
An array is defined using the keyword “array”. Each element of line array is assigned on
index values which commences from O and ends with n-1. The user can access the array
element using the array name followed by index value.
Example:
<?php
$teacher_name=array(“raja”, “hari”, “nm”);
echo “The teachers name are “ . $teacher_name[0] . “, “ . $$teacher_name[1] . “ and “ .
$teacher_name[2] . “.”;
?>
2. What is Associative Arrays ?
Associative arrays are a key-value pair data structure. Instead of 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.
SYNTAX:
Associative Arrays Syntax
array(key=>value,key=>value,key=>value,etc.);
key = Specifies the key (numeric or string)
value = Specifies the value
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”;
?>
3. What is 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
$student=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>”;
?>
===================
5 MARKS:
1. 1. DEFINE USER DEFINED FUNCTION?
User Defined Function
User Defined Function (UDF) in PHP gives a privilege to user to write their own specific operation inside of existing program module.
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;
}
Example:
<?php
function Msg() {
echo “HI FRIENDS...”;
}
Msg();
?>
2. 1. WHAT IS PARAMETERIZED FUNCTION?
Parameterized Function
Values can be passed from one function to another function thru parameters. 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.
Example 1:
The following example has a function with one Argument ($sfname):
<?php
function School_Name($sname) {
echo $sname.”in Tamilnadu.<br>”;
}
School_Name (“Government Higher Secondary School Madurai”);
School_Name (“Government Higher Secondary School Trichy”);
?>
CLICK ANY ONE AD BEFORE DOWNLAD
PDF DOWNLOAD:
Tweet |
No comments:
Post a Comment
உங்கள் கருத்துகளை சொல்லுங்கள்