Archimedes
Jul 31 2008, 04:17 PM
Well, the last lesson was on If...Else statements, this one will be on Functions. Things you need to know1.Basic PHP(Lesson 1) 2.I only speak English, sorry. So, everything will be in English terms. 3.I only put the stuff in quotes to be more organized. xD Lesson #3;Functions!Questions & AnswersQ1.What is a function? A1.A function is code that we can access at any time, such as the e-mail function; mailto(email@something.com). Q2.Why use functions? A2.Would you rather use CODE <?php
lots and lots of code more code more and more code
?> or function()? Making functions1.To create a function, simple type function function_name() { what it does; }2.Say I wanted to make a function that says "Astahost is the best host ever deal with it!", and named astahost(), it would look like this. CODE <?php function astahost() { echo "Astahost is the best host ever deal with it!"; }
astahost(); ?> [b]Output:[/b] Astahost is the best host ever deal with it! 3.That was a fairly simple function, let's move onto something a bit more, not so simple. [/quote] [quote] [b]More complex functions[/b] 1.Can have If...Else statements in it. 2.Making a function say different things. [code] <html> <body>
<?php function host($abc) { echo $abc . " is a great web host!<br />"; }
host("AstaHost");
host("Trap17"); - host("Computing Host"); ?>
</body> </html> Output:AstaHost is a great web host! Trap17 is a great web host! Computing Host is a great web host![/quote] [quote] How to use your own collection of functions1.Simply create a file called functions.php, or anything else, just remember it. 2.Make your own functions on that file, xD. 3.Here is my math_functions.php CODE <?php //adding function add($x,$y) { $total = $x + $y; echo $total ."<br />"; }
//subtracting function subtract($x,$y) { $total = $x - $y; echo $total ."<br />";
}
//multiplying function multi($x,$y) { $total = $x * $y; echo $total ."<br />";
}
//dividing function divide($x,$y) { $total = $x / $y; echo $total ."<br />";
} ?> 4.To use that in a page, simply do CODE <html> <body> <?php include("math_functions.php"); ?> <p> 4+4= <?php add(4,4); ?><br /> 4-4=<?php subtract(4,4); ?><br /> 4*4=<?php multi(4,4); ?><br /> 4/4=<?php divide(4,4); ?><br /> </p> </body> </html> {had to separate them by ending the <?php over and over, the answer was not going where it should, lol} Output:4 + 4 = 8 4 - 4 = 0 4 * 4 = 16 4 / 4 = 1 Well, that's it. Next lesson will be on PHP forms, maybe.
Reply
Recent Queries:--
speaking function php - 159.75 hr back. (1)
-
cannot call file-functions in "own functions" php - 227.38 hr back. (1)
Similar Topics
Keywords : php, lesson, 3, functions, php,
- Time Functions Needed
(9)
Basic C Language, Functions
(5) In a complicated and/or big C programs, a programmer might need to use the same peice of code more
than one time. However repeating the code can be both time consuming and frustrating. Thats why we
use functions. Definition: A function is a small subprogram having its own name and datatype. It
is used to carry out certain operations more than one time without the need of repetition. One of
the functions we all know is the main functions; void main(). I will explain the void later.
Syntax: Each function is composed of 3 parts: Name of the function Info type of the....
String Library Functions
A few questions (4) Hi everyone, I have a NEW question I am learning about strings and I don't understand what some
string functions are... strcpy() strcat() strcmp() and strlen() "C++ Beginner's Guide by
Herbert Schildt" explained what the functions do but I am still confused. I read the functions many
times and looked up examples... If you can explain what each of them are and do, I would be
grateful. Thanks in advance! ....
Php: Lesson #2; If...else Statements.
Basics of If...Else statements. (1) Alright, this is part #2 of my PHP Lessons. We will go into depth with more of the, scripting part
of PHP. Things you should know. 1. Basic PHP 2. Understanding of scripting. If...Else statements
1. If...Else statements are used if you want your script/scripts to do something based on a
variable. CODE if (condition) code to be done if condition is true; else code to be done if
condition is false; ?> 2. With that, you're probably a bit still confused as to what it's
doing, I was too at first. Look at the next code for a better explanation. This is if t....
Php:lesson #1
The basics of PHP. (4) First off, we need to meet each other. I am Archimedes! xD I chose this name because I have a joy
for mathematics and calculators and such. Archimedes is the man who discovered Pi(3.14159). Things
you should know before we start Lesson #1. 1.HTML 2.General scripting knowledge or what it actually
does. Alright, to the PHP lessons. 1.PHP stands for PHP; Hypertext Preprocessor. 2.PHP is used
all around the world to build dynamic web pages and web sites. Basic Syntax 1. All PHP scripts
start with the 2. To write something in PHP, we use the 'echo' or 'pr....
Lesson Of The Day
daily lessons of life, love and all that inbetween (5) I have been learning many things through out my life, whether I wanted to learn the lesson or not.
Well today I'm want to tell you about what I learned about drinking. I'm sure at this point
your think WFT is he talking about what can you learn from that. You see in my case I never drank
so when I first did I didn't have anyone to tell me the do's and don't of drinking. So
today I will share with you what I learned and I learned it the hard way. First of I'll tell
you the story of how I arrived to this lesson. I had just arrived at my firs....
Using Regular Expressions To Parse Functions
(6) I have a hierarchy of functions represented as something like:-
@BeforeText(@AfterText(@ReadURL('http://www.quotationspage.com/quote/1.html')@,'
',True)@,' ',True)@ Each of the functions follow the format @FunctionName( )@. The
ParamString itself can be composed of a string, a number or a boolean value. For example:-
@AfterText('String', "st", True)@ - This function returns the portion of text following the
specified substring. It is composed of three parameters. First one is the string being worked on,
second is the substring being sou....
Creating Dll With Delphi
show how to pass functions and procedures in DELPHI (0) First of all, I'd like to apologise because my English is not tha good. Well, It's a very
popular doubt. like How can I use a DLL? How can I create one? What is it for? So, DLL or Dynamic
Link Libraries, allows a set of functions developed in one especific programmer language to be used
for softwares developed in other language. For example, you can create a DLL in DELPHI and use it
with a software developed in C++ for example. So, let's get started: Select the Item NEW in the
menu FILE to show the dialog box NEW ITEMS. Now select DLL and OK to generate ....
Random With Functions?
(4) Hey! Is it possible to use a random script on functions. Lets say I have created three functions
(Items that a user will win if he defeates a monster). One function is a function named shield()
and another function is named sword() and a third function is named helmet(). Now when a player
defeates a monster, he must be awarded. So.. How can I randomize what item he should get? something
like CODE rand(sheild(), sword(), helmet()); or? Thanks //Feelay....
Network Outage. Distribution Switch Ddosed.
Lesson Learnt (5) The Distribution Switch to which our network is connected was DDOSed causing a partial network
failure. The entire downtime was reduced due to our DNS shift in Dec 2007. We regret to inform that
today at about 11 AM IST, We started experiencing a network lag. By 12.30 PM IST, the network was
down partially with most of our servers affected except Zeta and Mu. By 1.00 PM IST, the entire
network had gone down and was recovered slowly by 2.00 PM IST. By 2:30 IST, the network was
completely recovered and all servers were operating smoothly. FULL STORY: http://www.x....
C# Tutorial : Lesson 9 - Constructors & Destructors
(0) The need for Initialization A class contains data members (variables) and member
functions. Initializing the values of these data members is essential, at times. Take a look at the
following scenarios:- CODE int MyNumber; Console.WriteLine("My Number = {0}", MyNumber);
This block of code declares a variable MyNumber and then prints it on the screen. However, when
you try to execute these instructions, an error Use of unassigned local variable 'Product'
will be generated. This is because, we are trying to use the value of MyNumber , even be....
C# Tutorial : Lesson 8 - Functions/methods
(0) The programming model has gone through many refinements, each change improving upon the model. One
of the early changes was the inclusion of Subroutines or Subprograms. As the names suggest, these
are fragments of code within a program. They offer the following advantages:- Reduction of code
duplication by offering re-usability Simplifying program logic by decomposing the program into
smaller blocks Improving readability of the program Why do we need functions?
Consider the following program:- CODE using System; namespace ConsoleApplication1 { ....
C# Tutorial : Lesson 7 - Creating Value Types & Reference Types - Part II
(1) foreach statement This statement is explicitly used to traverse through arrays. The
benefit of using foreach over the normal for statement is that it is not needed to check the
size of the array while using the former. Syntax:- foreach(type identifier in expression) {
statement 1; statement 2; .... } Suppose we have an array StudentNames containing the name of all
the students in a class. We need to display the name of each one of them on screen. First we will
see how it can be done using the for loop. CODE string StudentNames = new string {"....
C# Tutorial : Lesson 6 - Creating Value Types & Reference Types - Part I
(0) Value Types & Reference Types In C#, Variables are either value types or reference types
depending on what they store, values or references. By reference we imply that the variable holds
the memory address of another location where the actual value is stored. All built in data types -
Int, Char, String, Float, Boolean, etc are value types while classes are reference types. The
following is a diagrammatic representation of these two types. In this picture there are two
variables Num1 and Num2. Both of these being integer variables store the values directly.....
Javascript Show / Hide Functions
need some fine-tuning (3) Searching before posting my topic, i found this very helpful post. Javascript show + hide
However, I'm still muddling around trying to fine tune it, and since i'm no good at coding,
I'd appreciate any help. Using that example, how do I get the div text to be hidden on loading,
rather than showing it all at page load. Also, is there a way to have the text change when clicked?
so that for example, it would say "expand" when it's the small amount of text, and "collapse"
when it's the full text? ....
C# Tutorial : Lesson 5 - Encapsulation & Abstraction
(0) Encapsulation & Abstraction Two concepts that go together in the object oriented approach
are Encapsulation & Abstraction. Abstraction is the representation of only the essential features of
an object, while Encapsulation is the hiding of the non-essential features. Think of a person
driving a car. He does not need to know the internal working of the engine or the way gear changes
work, to be able to drive the car (Encapsulation). Instead, he needs to know things such as how much
turning the steering wheel needs, etc (Abstraction). Consider the example from ....
C# Tutorial : Lesson 4 - Object Oriented Programming
(2) Object Oriented Programming Object Oriented Programming is a methodology modeled on real
life. It comprises of the basic unit, an object, being used in implementing a program. Think of all
the objects around you - cars, buses, birds, trees, etc. You will find countless ones of them,
everywhere you go. In order to tackle this huge number, we started classifying them, thus came the
term Class. Class A class is a composition of the theoretic characteristics (attributes and
properties) of an object and the things it can do - behaviors, methods and features. Tak....
C# Tutorial : Lesson 3 - Programming Constructs
(1) Conditional Branching By branching we imply, having different paths for execution.
Conditions are used to determine which statements need to be executed. Suppose, you have a program
to store the details of employees. Depending upon the post of the employee, there would be various
fields associated with it. A department head, for example, would have a property denoting the
department he heads, etc. We use conditional branching in such a scenario. C# provides the
following conditional constructs:- if .. else Syntax:- if ( ) { statements } else { statement....
C# Tutorial : Lesson 2 - Variables & Operators
(0) Variables A Variable is a named location that stores a value. Although variables are
physically stored in the RAM, their actual memory address is not known to the programmer. We can use
the variables via the name we give them. These are the rules for naming a variable:- The name must
begin with a letter or an underscore & can be followed by a sequence of letters (A-Z), digits (0-9)
or underscore (_) Special Characters such as ? - + * / \ ! @ # $ % ^ ( ) { } , ; : . cannot be
used in the variable name. A variable name must not be the same as a reserved k....
C# Tutorial : Lesson 1 - Hello World Program
(0) This is the first installment of my venture to explain the bits and pieces of C# that I have managed
to learn at NIIT. In this lesson we would be creating the Hello World application. STEP 1 : Create
a New Console Application in Visual C# The IDE automatically adds the following code:- CODE
using System; using System.Collections.Generic; using System.Text; namespace HelloWorld {
class Program { static void Main(string args) { } } } Lets
take a look at the first 3 lines. All of these lines begin with the keyword using....
Writing Functions In PHP
Turn Your PHP Script Into A Reusable PHP Function (6) Well, it has been a while since I offered a tutorial here at AstaHost. Most of my creativity has
gone toward my new website, Handy PHP . The website is just getting started and it is hard to post
potential content for my website here instead of there. The purpose of this tutorial is to show you
how to convert a standard PHP script into a reusable PHP function. It is funny, because this
tutorial is very similar in nature to the very first tutorial I wrote here. Rapid HTML code
generation using simple PHP would be a good topic to read with this tutorial. Before we....
C++: Basic Classes
classes, objects, access labels, members, inline functions (5) This tutorial assumes that you have a basic knowledge of C++. You know how to use built-in types,
like ints, doubles, chars, etc. You should know some types that are part of the STL, like vector,
etc. Those types that come in the STL are just C++; you can create your own types just like those!
Non built-in types are referred to as classes . To create a class, you just use the keyword class
, the name of the class, and curly brackets. CODE //A class named MyClass class MyClass { };
In fact, that is all we need to create variables, pointers, or references to t....
Programming In Glut (lesson 6)
Texture filters and lighting (1) This tutorial demonstrates how to use texture filters and will let you see the differences of each
filter. I will also be introducing lighting into this tutorial. We first have to create our
"bitmap.h" header file with the functions we use to load our bitmaps, this is changed from the last
tutorial to fit the needs of this one. The first thing to do is to link all of our OpenGL libraries
and include our needed headers for the functions we will call. CODE #pragma comment(lib,
"opengl32.lib")//Link to the OpenGL libraries #pragma comment(lib, "glu32.lib") #pragma....
Programming In Glut (lesson 4)
Making 3D objects (7) Hello, in this tutorial we will be creating a 3D pyramid. We are building this tutorial from Lesson
3, but I took out the 2D objects and placed a 3D pyramid in there instead. The 3rd axis for drawing
can be a litle confusing, but after you get the hand of it you'll do fine. Now when you are
setting a 3D vertex just remember that the camera is on the positive end of the z axis. So things
that have a more positive z axis value are closer than verteces with a more negative value. Well
let's get started We always start by including the glut library CODE #i....
Programming In Glut (lesson 3)
How to animate objects in GLUT (1) In this tutorial I am going to talk about how to get animation in your program. I will be working
directly off of Lesson 2 and will now take out the notes left behind from Lesson 1, but I will leave
the notes from Lesson 2. CODE #include //include our glut library First we are going to
initialize a variable called "time" which will record how much time has passed so we can use it to
determine how to animate the objects. Then we have our init function that initializes some stuff in
GLUT CODE float time = 0;//(NEW) variable to record the how much time has....
Programming In Glut (lesson 2)
Learn how to draw 2D polygons in this tutorial (8) This is the second lesson in my series of tutorials on how to use GLUT to create graphics. In this
tutorial I am going to be teaching you how to create different types of polygons. I am going to be
adding on to last tutorial's code and will leave the notes in to help you remember what all the
function are. I will also be noting the new functions that we will be using and how to use them.
CODE #include //Include the GLUT functions This time we are going to not only set the
background color, but set the area that we are viewing as well. gluOrtho2D(); sets....
Programming In Glut (lesson 1)
The first of a series of tutorials on how to use the OpenGL Utility To (3) Hello, I'm starting a series on how to program in OpenGL using the OpenGL Utility Toolkit,
a.k.a. GLUT. I chose GLUT because it is quick and easy to write, and very easy to learn. In this
tutorial I am going to teach you how to create a basic window which we will build off of in later
tutorials. Throughout the tutorial I will leave notes to let you know what each command does, and
how you can modify it to fit your needs. Everything in the code section can be copied and pasted
into your compiler and it should compile proporly, if it does not, please let me know, a....
Lesson #2 - Switch Statement In C#
Using the Switch Statement in C# (1) In the previous lesson we demonstrated did a basic input output application which asked your your
name and replied with a general greeting using the name you entered. In this lesson we are going
to learn about a conditional statement called the switch statement. Usually if and if else
statements are taught before switch statements. Although these are very useful, I find the switch
to be easier and more fun to use. The program written below is very similar to the previous
program where the user is asked to enter their name, however now the program will loo....
Lesson #1 - Introduction To C#
Console Application (1) This tutorial will help get you started with C# Sharp. These tutorials will assume that you are
using the Visual Studio environment. If you are just curious to test out some code, then you can
copy and paste this code into your CS file, however, before doing so, make sure to name your project
the same as the namespace on the code. But since this first program is fairly easy, it will not
hurt to type it out. It is fairly easy and short. Also, this program is highly commented so it
should be easy to follow along. Comments will have 2 forward slashes before them '....
Php : Variables Included Dont Work In Functions
Variables from Included files dont work (4) Today, I came up with this strange PHP behaviour. Just wanted to know if anyone has any
suggestions! I make a common variable/function file called config.php. I put in my generally used
functions in it. Suppose this is my file // -----VARIABLES --- // $a=10,$b.... //
-----FUCTIONS--- // function doit() { print "A value is " . $a; } ?> Here, suppose we execute
this file directly. Since A has a global scope, it does work perfectly. But if this same file is
imported in another file say, mainfile.php // -----VARIABLES --- // $c,$d.... include
'config.ph....
Looking for php, lesson, 3, functions, php,
|
*SIMILAR VIDEOS*
Searching Video's for php, lesson, 3, functions, php,
|
advertisement
|
|