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
    289
    Thanks
    2
    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. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    6,490
    Thanks
    30
    Thanked 887 Times in 885 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.
    Physics is actually atoms trying to understand themselves.


 

Posting Permissions

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