Results 1 to 3 of 3

Thread: in_array problem.

  1. #1
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default in_array problem.

    Hello,

    I am simply trying to see if a value exists in an array of external file read by the file() function but unfortunately neither the in_array function is working nor the search_array. My code looks like this.

    PHP Code:
    <?php
    //$arr = array('red', 'green', 'blue');
    $arr file('colors.txt');
    if(
    in_array('green',$arr)){
    echo 
    "Fount at index:".in_array('green',$arr);
    } else {
    echo 
    "Not found";
    }
    ?>
    txt file, colors.txt

    Code:
    red
    green
    blue
    green
    It works with the arrays created with the array function but not with the file function any help would be appreciated. Thanks.

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by shachi
    I am simply trying to see if a value exists in an array of external file read by the file() function but unfortunately neither the in_array function is working nor the search_array.
    As stated in the manual, the array elements created by the file function including the new line characters that were present in the file. You haven't taken that into consideration.

    Mike

  3. #3
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your reply but I have already solved the problem.

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
  •