 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,

Slides:



Advertisements
Similar presentations
Spring Semester 2013 Lecture 5
Advertisements

Outline What Is Function ? Create Function Call Function Parameters Functions Function Returning Values PHP Variable Scopes Passing by Reference Vs Value.
Functions ROBERT REAVES. Functions  Interface – the formal description of what a subprogram does and how we communicate with it  Encapsulation – Hiding.
ITC 240: Web Application Programming
Functions Section 4.3. Last week, we were introduced to procedures Procedures are used in support of top- down program design. –They are used to create.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
INTERNET APPLICATION DEVELOPMENT For More visit:
Why to Create a Procedure
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
Chapter 2 User_defined Function. Chapter Goals In this chapter, you’ll learn all about PHP functions, including how : to create and invoke them, pass.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
CPS120: Introduction to Computer Science Lecture 14 Functions.
PHP Constructs Advance Database Management Systems Lab no.3.
Slide 1 PHP Arrays and User Defined Functions ITWA133.
JavaScript III Functions and Abstraction. 2 JavaScript so far statements assignment function calls data types numeric string boolean expressions variables.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
COMPUTER PROGRAMMING. Functions’ review What is a function? A function is a group of statements that is executed when it is called from some point of.
Python Functions.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
Outline if...else...elseif Statements Switch Loops Functions Arrays Forms.
PHP Function. Outline o What Is Function ? o Create Function o Call Function o Parameters Functions o Function Returning Values o Passing by Reference.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
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.
1 JavaScript Part 3. Functions Allow the user to decide when a particular script should be run by the browser in stead of running as long as the page.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
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.
FUNCTION Functions is a sub-program that contains one or more statements and it performs some task when called.
PHP Variables.  Variables are "containers" for storing information. How to Declare PHP Variables  In PHP, a variable starts with the $ sign, followed.
 A PHP script can be placed anywhere in the document.  A PHP script starts with  The default file extension for PHP files is ".php".  A PHP file normally.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
Creating FunctionstMyn1 Creating Functions Function can be divided into two groups: –Internal (built in) functions –User-defined functions.
Programming Fundamentals Enumerations and Functions.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
11 – Introduction to PHP(1) Informatics Department Parahyangan Catholic University.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
ITM 3521 ITM 352 Functions. ITM 3522 Functions  A function is a named block of code (i.e. within {}'s) that performs a specific set of statements  It.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
PHP using MySQL Database for Web Development (part II)
PHP Built-In Functions
>> Fundamental Concepts in PHP
Functions A function is a block of code with a name. function functionName() { code to be executed; }
CHAPTER 5 SERVER SIDE SCRIPTING
PHP Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used repeatedly in.
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
PHP Functions, Scope MIS 3501, Fall 2015 Jeremy Shafer
For Loops October 12, 2017.
Introduction to Web programming
PHP.
MCS/BCS.
Basics (Cont...).
Tutorial 6 PHP & MySQL Li Xu
Topics Introduction to Functions Defining and Calling a Function
Flow of Control.
COMPUTER PROGRAMMING SKILLS
PHP an introduction.
Methods/Functions.
PHP Function and Array 05 CHAPTER Padasalai MOHAMED FAKRUDEEN
ITM 352 Functions.
 A function is a named sequence of statement(s) that performs a computation. It contains  line of code(s) that are executed sequentially from top.
Selamat Datang di “Programming Essentials in Python”
Presentation transcript:

 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, we can create our own functions.  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.

 A user defined function declaration starts with the word "function": Syntax  function functionName() { code to be executed; }

 A function name can start with a letter or underscore (not a number).  Give the function a name that reflects what the function does.  Function names are NOT case-sensitive.

OutPut Welcome to PHP Page

 Information can be passed to functions through arguments. An argument is just like a variable.  Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma.

 The following example has a function with one argument ($fname). When the familyName() function is called, we also pass along a name (e.g.Ali), and the name is used inside the function, which outputs several different first names, but an equal last name:  "; } familyName(“Ali"); familyName(“Usman"); familyName(“Hafeez"); ?>

 Output: Ali Ahmed Usman Ahmed Hafeez Ahmed

 "; } familyName(“Ali", "1975"); familyName(“Usman", "1978"); familyName(“Hafeez", "1983"); ?>

Output: Ali Ahmed. Born in 1975 Usman Ahmed. Born in 1978 Hafeez Ahmed. Born in 1983

 The following example shows how to use a default parameter. If we call the function setHeight() without arguments it takes the default value as argument: "; } setHeight(350); setHeight(); // will use the default value of 50 setHeight(135); ?>

 Output : The height is : 350 The height is : 50 The height is : 135

 To let a function return a value, use the return statement: "; echo " = ". sum(7, 13). " "; ?>

 Output: = = 20