PHP Function and Array 05 CHAPTER Padasalai MOHAMED FAKRUDEEN

Slides:



Advertisements
Similar presentations
Subprograms Functions Procedures. Subprograms A subprogram separates the performance of some task from the rest of the program. Benefits: “Divide and.
Advertisements

Arrays.
Procedures and Functions. What are they? They are both blocks of code that can be reused to perform specific task. However there is a difference: Function-
1.
Road Map Introduction to object oriented programming. Classes
VBA Modules, Functions, Variables, and Constants
1 Modularity In “C”. 2 What is Modularity?  Modularity, is the heart of the high level, structured languages.  Means breaking down a big problem into.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Java Unit 9: Arrays Declaring and Processing Arrays.
Python quick start guide
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
IE 212: Computational Methods for Industrial Engineering
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
Chapter 6 Sub Procedures
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Chapter 8: Arrays and Functions Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Slide 1 PHP Arrays and User Defined Functions ITWA133.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
PHP. PHP User Defined Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
Functions  A Function is a self contained block of one or more statements or a sub program which is designed for a particular task is called functions.
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
 The real power of PHP comes from its functions; it has more than 1000 built-in functions.  PHP User Defined Functions  Besides the built-in PHP functions,
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Programming Right from the Start with Visual Basic .NET 1/e
Subprograms Functions Procedures.
Programming Logic and Design Seventh Edition
Topics Introduction to Functions Defining and Calling a Void Function
CHAPTER 4 CLIENT SIDE SCRIPTING PART 3 OF 3
Arrays An array in PHP is an ordered map
CHAPTER 5 SERVER SIDE SCRIPTING
Spreadsheet-Based Decision Support Systems
Objectives Identify the built-in data types in C++
Functions Chapter 6-Part 2.
Chapter 3: Using Methods, Classes, and Objects
JavaScript: Functions
Functions.
Prepared By: G.UshaRani B.Pranalini A.S.Lalitha
JavaScript: Functions.
11/10/2018.
Arrays, For loop While loop Do while loop
VISUAL BASIC.
Chapter 6 Sub Procedures
Introduction to Web programming
7 Arrays.
PHP.
Data Structures (CS212D) Week # 2: Arrays.
MCS/BCS.
Basics (Cont...).
Arrays Week 2.
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Single-Dimensional Arrays chapter6
Week 4 Lecture-2 Chapter 6 (Methods).
CIS16 Application Development and Programming using Visual Basic.net
7 Arrays.
Topics Introduction to Functions Defining and Calling a Function
COMPUTER PROGRAMMING SKILLS
PHP an introduction.
PHP CONDITIONAL STATEMENTS
LOOPING STRUCTURE Chapter - 7 Padasalai
CPS125.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Chapter 6: Methods CS1: Java Programming Colorado State University
Presentation transcript:

PHP Function and Array 05 CHAPTER Padasalai MOHAMED FAKRUDEEN PGT-COMPUTER SCIENCE SHAMROCK MATRIC. HR. SEC. SCHOOL MOGAPPAIR, CHENNAI-107

MOHAMED FAKRUDEEN 7/7/2019 LEARNING OBJECTIVES To understand the importance of Functions concept in PHP To know the types of functions concept in PHP To know the basics of array concepts To know the types of Arrays concept in PHP

MOHAMED FAKRUDEEN 7/7/2019 Functions in PHP

MOHAMED FAKRUDEEN 7/7/2019 What is Function? In most of the programming language, a block of segment in a program that performs a specific operation tasks such as Insert Execute Delete Calculate etc. This segment is also known as Function.

What is Function? (Cont…) MOHAMED FAKRUDEEN 7/7/2019 What is Function? (Cont…) 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

MOHAMED FAKRUDEEN 7/7/2019 Types of functions The Function can be divided in to three types as follows User defined Function Pre-defined or System or built-in Function Parameterized Function.

MOHAMED FAKRUDEEN 7/7/2019 User defined Function

MOHAMED FAKRUDEEN 7/7/2019 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 Function Calling

MOHAMED FAKRUDEEN 7/7/2019 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; }

MOHAMED FAKRUDEEN 7/7/2019 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 - Program <?php function insertMsg() { MOHAMED FAKRUDEEN 7/7/2019 Example - Program <?php function insertMsg() { echo “Student Details Inserted Successfully!”; } insertMsg(); // call the function ?>

Parameterized Function MOHAMED FAKRUDEEN 7/7/2019 Parameterized Function

Parameterized Function MOHAMED FAKRUDEEN 7/7/2019 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.

MOHAMED FAKRUDEEN 7/7/2019 Example – Program 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”); School_Name (“Government Higher Secondary School Chennai”); School_Name (“Government Higher Secondary School Kanchipuram”); School_Name (“Government Higher Secondary School Tirunelveli”); ?>

MOHAMED FAKRUDEEN 7/7/2019 Example – Program 2 The following example has a function with two arguments ($sname and $Strength): <?php function School_Name($sname,$Strength) { 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); ?>

MOHAMED FAKRUDEEN 7/7/2019 Example - Program3 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); ?>

MOHAMED FAKRUDEEN 7/7/2019 ARRAYS IN PHP

MOHAMED FAKRUDEEN 7/7/2019 What are arrays? 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.

MOHAMED FAKRUDEEN 7/7/2019 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.

Indexed Arrays Array Syntax: Array defines with the keyword array() MOHAMED FAKRUDEEN 7/7/2019 Indexed Arrays Array Syntax: Array defines with the keyword array()

Example: <?php $teacher_name=array(“Iniyan”, “Kavin”, “Nilani”); MOHAMED FAKRUDEEN 7/7/2019 Example: <?php $teacher_name=array(“Iniyan”, “Kavin”, “Nilani”); echo “The students name are “ . $teacher_name[0] . “, “ . $$teacher_name[1] . “ and “ . $teacher_name[2] . “.”; ?>

MOHAMED FAKRUDEEN 7/7/2019 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.

Syntax array(key=>value,key=>value,key=>value,etc.); MOHAMED FAKRUDEEN 7/7/2019 Syntax array(key=>value,key=>value,key=>value,etc.); key = Specifies the key (numeric or string) value = Specifies the value

MOHAMED FAKRUDEEN 7/7/2019 Example: <?php $Marks=array(“Student1”=>“35”,“Student2”=>“1 7”,“Student3”=>“43”); echo “Student1 mark is” . $Marks[‘Student1’] . “ is eligible for qualification”; echo “Student2 mark is” . $Marks[‘Student2’] . “ is not eligible for qualification”; ?>

Multidimensional Arrays MOHAMED FAKRUDEEN 7/7/2019 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.

<?php// A two-dimensional array $student=array ( MOHAMED FAKRUDEEN 7/7/2019 <?php// A two-dimensional array $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] echo $$student[2][0].”: Tamil Mark: “.$student [2][1].”. English mark: “.$student [2] ?>

POINTS TO REMEMBER PHP Functions are Reducing duplication of code MOHAMED FAKRUDEEN 7/7/2019 POINTS TO REMEMBER 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 PHP arrays are using For each looping concepts

CONDITIONAL STATEMENTS MOHAMED FAKRUDEEN 7/7/2019 NEXT TOPIC: CONDITIONAL STATEMENTS