Ok, well I was bored and decided to write this.
Classes are mainly used when you have lots of functions doing stuff for the same thing, e.g. you might have functions which displays the users level, username etc, so instead of indivitual ones you can group them together in a class.
Lets learn about functions:
Functions are used to make up your own functions hidden away in a file so no one looks at your rubbish coding and only see a good function (well for me it is..)
Anyway, in your function you can use allready made functions like this:
Lets split it down!PHP Code:<?php
function my($mum, $likes, $you)
{
if($mum == "is" && $likes = "your" && $you == "lover")
{
echo $mum;
echo $likes;
echo "<br />";
echo $you;
}
}
my("is", "your", "lover");
?>
That defines the functions name, and what variables to use in itPHP Code:function my($mum, $likes, $you)
{
If your using functions you should know what it does, but it uses the variables defined in the functionPHP Code:if($mum == "is" && $likes = "your" && $you == "lover")
{
Echos the variables in the functionsPHP Code:echo $mum;
echo $likes;
echo "<br />";
echo $you;
Ends the function and the if, and uses the functions.PHP Code:}
}
my("is", "your", "lover");
Ok, now onto classes:
If you had multiple functions (these will just be the same)
You would do this:
I dont really need to explain it, as if you know PHP and are using classes you would understand it.PHP Code:<?php
class mum
{
function my($mum, $likes, $you)
{
if($mum == "is" && $likes = "your" && $you == "lover")
{
echo $mum;
echo $likes;
echo "<br />";
echo $you;
}
}
function ha($mum, $likes, $you)
{
if($mum == "is" && $likes = "your" && $you == "lover")
{
echo $mum;
echo $likes;
echo "<br />";
echo $you;
}
}
}
$any variable name here = new classnamehere(mum in our case)();
$the same variable as above->functionname("is", "your", "lover");
$the same variable as above->functionname("is", "your", "lover");
// So it would be:
$example = new classnamehere(mum in our case)();
$example->my("is", "your", "lover");
$example->ha("is", "your", "lover");
?>
Edited by Nick- (Forum Super Moderator): Thread moved from Website Designing.





Reply With Quote





