SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hi, simple issue with math?

    I am trying out PHP
    I am not quite sure why this happens.. but
    This is what I have in my test.php file

    <?
    if ($function = "addition") { echo $num1 + $num2; } elseif ($function = "subtraction") { echo $num1 - $num2; }
    ?>

    So I try test.php?num1=4&num2=2&function=subraction
    and it gives back 6..
    I don't know why. help please! =)

  2. #2
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Replace each '=' sign with '==' sign. That's simple.

  3. #3
    SitePoint Enthusiast JohnInFl's Avatar
    Join Date
    Sep 2001
    Location
    FL, USA
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool

    I was thinking the same thing replace = with ==. Most languageslike C++ or Perl would be == for testing for a boolean equals. If you just use = it will assign it that value even if t is within a conditional block of code.

  4. #4
    SitePoint Addict IsaacV's Avatar
    Join Date
    Jan 2002
    Location
    Saint Petersburg
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that's right.
    Pants.
    Join the NYFlava Fashions Contest


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •