Thread: variables

    #1
  1. Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    49
    Rep Power
    15
    I know I really should know this, in fact i don't know how I got away without it before, but i have some questions concerning the way variables work in PHP...

    * how do I set an if condition for one variable to be like another - as in how do i say "if ($1 = $2){}" - is that correct ?

    * how do I set an if condition for a variable to be equal to either a number or a text content ? For example "if ($1 = 1){}" or "if ($1 = "foo"){}"

    This last one would be for use with a form - say i set [abbreviated code]
    <select name="find"
    option value="foo"
    option value="bar">

    then on the page that form takes us to, I say
    if ($find = "foo") {echo "foo";}
    if ($find = "bar") {echo "bar";}

    This does not seem to work ;(

    any ideas why or how to do it properly ?


    cheers,
    nick
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    24
    Rep Power
    0
    Try:

    if ($find == "foo") {echo "foo";}
    if ($find == "bar") {echo "bar";}

    = is the assignment operator, whereas == is the comparison one. Hope this helps.


    ------------------

    - weeder

Similar Threads

  1. Passing POST variables
    By rlorenzo in forum PHP Development
    Replies: 11
    Last Post: June 6th, 2004, 02:00 PM
  2. help with assigning variables, variable passing/ retrieval
    By pinkipodmini in forum PHP Development
    Replies: 0
    Last Post: February 13th, 2004, 09:40 PM
  3. Replies: 2
    Last Post: February 10th, 2004, 11:03 PM
  4. functions and variables
    By uniopp in forum PHP Development
    Replies: 7
    Last Post: September 25th, 2003, 09:43 AM
  5. Automatically creating class variables
    By dreamstring in forum PHP Development
    Replies: 1
    Last Post: August 15th, 2003, 09:12 AM

IMN logo majestic logo threadwatch logo seochat tools logo