Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    simple hangman game. How do i check to see if the letter is in the array [0]

    this is as far as i could get with the checking part. this isn't homework or anything just fun.

    $guess = ($_POST['guess']);

    $wds = array(rat, cat, mouse, meow, tree, house, goat, hat, grass, people, spider);

    if ($turn == 11 Xor $word == "correct"){
    shuffle ($wds);
    }
    $check = array($spwds);

    thank you in advance

  • #2
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    use the in_array(); function
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    but wont they have to use a whole word rather than one letter

  • #4
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    are you trying to search for one letter in a word of an item of the array or search in the array for a word for them to enter?

    Would you be able to post the whole code as the code in post #1 $spwds and that var hasn't been set in the code.
    Last edited by DJCMBear; 06-10-2010 at 11:58 AM.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #5
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    im trying to search for one letter of an item in the array.

  • #6
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    $find = 'something';
    
    foreach ($wds as $key => $val)
    {
        if (strpos($val, $find) !== false)
        {
            [code for a match found here]
        }
    }

  • #7
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you.


  •  

    Posting Permissions

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