Qondio
Front
Intel
IntelMart
Shares
My Qondio
Account
hotnoob > Intel > Tut: Basic Functions with PHP

qondio.com/Q7ZA PRINT EMAIL

Tut: Basic Functions with PHP

Tutorial name: Functions with PHP
You're experience: Advanced
Difficulty: Average
Time Taken: 1-2 minutes
Plug-ins needed: none.


Functions with php are fairly simple.

First of all what is a function? it is a small tid bit of code that is ran each time it is called, and it allows for information to be returned, outputted, and inputted. In away, you can replace classes with functions, it ain't to hard, but it is possible. I use functions rather than classes because i feel more comfortable with them.

i will show you two things, how to use a function, and how to replace classes with them for developed coders, another time.

This will show you the basics to functions.
Code:
<?php
function repeatString($string, $times) // you can use what ever variables you want, and however many you want.
{
$count = 0;
while($count < $times)
{
echo"\n $string";
$count += 1;
}
}
?>
Blah blah blah...
<?php
repeatString("Hello!", 10); // this will echo "Hello!" 10 times
?>


returning variables
Code:
<?php
function 50Chance()
{
$rand = rand(0, 1);

return $rand;
]
?>
blah blah blah...
<?php
50Chance();
?>

//conditional functions
<?php
function ifGreaterThan0($num);
{
if($num > 0)
{
return 1;
}
else
{
return 0;
}
}

?>

A Noobs World © 2007-2008

Contributed by hotnoob on April 2, 2008, at 3:08 AM UTC.

Reactions

No reactions yet.

Rate This Intel

Please login or sign up to rate this intel.

Comments

Please login or sign up to add a comment.

Share

Copyright Notice

The copyright for this content entitled "Tut: Basic Functions with PHP" has been specified by the contributor as:

All Rights Reserved

This content may not be copied, distributed or adapted by anyone under any circumstances.

Login Here with
Any Email Address
Any Password
No account? Sign up.

Intel Contributor
This intel was contributed by hotnoob

Qondio Archive
May, 2012
123456
78910111213
14151617181920
21222324252627
28293031


2008
January, February, March, April, May, June, July, August, September, October, November, December
2009
January, February, March, April, May, June, July, August, September, October, November, December
2010
January, February, March, April, May, June, July, August, September, October, November, December
2011
January, February, March, April, May, June, July, August, September, October, November, December
2012
January, February, March, April, May

Sign Up
Not a member yet? Qondio is a powerful network for making it online. If you have a website to promote, we can help. Sign up and get in on the action.

About Qondio
Welcome to Qondio! Discover the awesome power this network can deliver by going to our About page. Or you could skip straight to the Sign Up form.

ABOUT
SUCCESS GUIDE
FEATURES
FAQ
ADVERTISE
CONTACT
USAGE POLICY
PRIVACY POLICY


TWITTER
FACEBOOK