Page 1 of 1

question about functions

Posted: Tue Jul 02, 2002 7:31 pm
by chris12295
I need to write a block of code and use it over and over in my script with a simple declaration. Kind of like functions in Javascript. Somthing like

function fizzlePants {

echo "blah"

}

if(blah) {
return fizzlePants
}

I know that wont work at all but its the concept im after. Can anyone help?

Posted: Tue Jul 02, 2002 7:46 pm
by hob_goblin

Code: Select all

function fizzlePants(){
echo "blah blah blah";
}

fizzlePants();

will print "blah blah blah"

Code: Select all

function fizzlePants(){
echo "blah blah blah";
}
if($blah){
fizzlePants();
}
will print "blah blah blah" if the variable Blah is true

Code: Select all

$blah = "ack";
function fizzlePants($foo){
echo "blah blah blah $blah $blah $blah";
}
if($blah){
fizzlePants($blah);
}
will print "blah blah blah ack ack ack" if the variable Blah is true..

i would still reccomend you read a tutorial on functions though... there is alot to say about them