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 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2010
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Searching an array of string with a word match

    Suppose I have this array
    PHP Code:
    $targetArray[]=" This is a big bird"
    And I have
    PHP Code:
    $txt="big"
    .
    How I can match the key word to the array? It should match because the array contains "big" word. Thanks.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,722
    Thanks
    25
    Thanked 662 Times in 661 Posts
    To start with you don't have an array. It should be:
    $targetArray = array("This", "is", "a", "big", "bird");

    Then you need the function in_array().

    PHP Code:
    <?php
    $targetArray 
    = array("This""is""a""big""bird");
    $txt="big";

    if (
    in_array($txt$targetArray)){
      echo 
    "Match found";
    }else{
        echo 
    "Match not found";
    }
    ?>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

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