Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2006
    Location
    Kent
    Posts
    987
    Tokens
    0

    Default Searching an array

    What would be the easiest way to search an array for a unique value, and then telling me what array key it is in. I've tried array_search but that doesn't seem to work, I think it's because i'm searching for a string, not exactly sure though. Each key of the array is structured like this
    PHP Code:
    "objectno";"objectname";"objectclassname";"objecttype";"description"
    I'm trying to search the whole thing for the objectno, and then tell me which key it is
    cheers for any help
    This is our situation and we're happy to be here,
    I wouldn't change this place for anything.


  2. #2
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    1,111
    Tokens
    100

    Latest Awards:

    Default

    errr i dnt get u but er


    in_array()

    ?

  3. #3
    Join Date
    Jan 2006
    Location
    Kent
    Posts
    987
    Tokens
    0

    Default

    http://uk.php.net/manual/en/function.array-search.php

    Well that function does exactly what I want it to do, but I cant get it to work
    This is our situation and we're happy to be here,
    I wouldn't change this place for anything.


  4. #4
    Join Date
    Jul 2008
    Location
    Leeds, UK
    Posts
    47
    Tokens
    0

    Default

    PHP Code:
    $search="2";
    $array=array("1;1name;1objectclass;1objecttype;1description;""2;2name;2objectclass;2objecttype;2description;""2;2name;2objectclass;2objecttype;2description;");
    $found=0;
    for(
    $i=0$i<count($array); $i++){
        if(
    preg_match("/".$search.";(.+?);(.+?);(.+?);(.+?);/"$array[$i])){
            
    $found=$i;
        }
    }
    echo 
    $found

Posting Permissions

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