Help with functions...pleasse!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevin
Forum Newbie
Posts: 3
Joined: Wed Jul 03, 2002 9:05 am
Location: UK

Help with functions...pleasse!

Post by kevin »

Hi all

In PHP created two functions and another section of code to call these function. However what I'm finding is that the first function is been called (which is wrong) the second function isn't been called (which is correct). But the code calling the functions are not been called. I' using PHPed if that helps.

I'm new to PHP and is trying to set something up using PHP and mySQL.

Any and all help will be greatly appreciated.
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Give us your code and it will be much easier to tell what's going wrong.
kevin
Forum Newbie
Posts: 3
Joined: Wed Jul 03, 2002 9:05 am
Location: UK

Help with functions...pleasse! 2

Post by kevin »

The general format of the code is like this....

function a()
{
echo "a-in";
// some other code
echo "a-out";
return(1); // exmaple return value
}

function b()
{
echo "b - in";
// some other code
echo "b-out"
return(0); // exmaple return value
}


// code to call functions

if (a)
{
ehco "a-called";
}


if (b)
{
ehco "b-called";
}

// the problem is that all I ever see is a-in a-out nothing else.
// hope this helps
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

I noticed a few things, like ehco instead of echo, no semicolon after echo b-out, and a instead of a(). The parenthesis tell PHP that a() is a function.

Try something like:

Code: Select all

$check = a();
if($check)
  echo "a has run";
$check = b();
if($check)
  echo "b has run";
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

In your example

Code: Select all

if(a)
    { echo "a-called"; }
Is "a" supposed to be a variable?

Later on,
BDKR
kevin
Forum Newbie
Posts: 3
Joined: Wed Jul 03, 2002 9:05 am
Location: UK

Help with functions...pleasse! 3

Post by kevin »

sorry for the crap syntax.
haven't programmed in C/C++ for years...I know about a() for functions instead of a. The syntax is correct. It's just the flow of execution that seems to be the problem. Learning to touch-type at the moment everything I type seems to come out crap.
defHex
Forum Newbie
Posts: 1
Joined: Wed Jul 03, 2002 4:44 pm

Post by defHex »

the code works as it should.

a() returns 1. and b() returns 0. 1 is the equivalent of true, and 0 is the equivalent of false.

if(true){
//gets executed
}
if(false){
//doesn't get executed
}

if you were trying to test if the functions a and b exist, use function_exists()......

-defHex
Post Reply