Simple array question.

Discussion in 'PHP' started by x0x, Nov 17, 2008.

  1. #1
    my array:

    $pupupu = array("admin","moderator");


    If($level == $pupupu) { blabla }


    The thing is. It does not work.

    It would only work as $pupupu[0] and $pupupu[1], but how can I make it that both will be called up with just pupupu?

    So pupupu would be admin or moderator.
     
    x0x, Nov 17, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    you can do foreach

    foreach($pupupu as $arraysss)
    {
    if($arraysss == $level)
    {
    code here...
    }
    }

    or

    $key = array_search($level, $pupupu);

    $key will return any dimension in the array $pupupu if found
     
    bartolay13, Nov 17, 2008 IP
  3. xenous

    xenous Peon

    Messages:
    102
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    maybe this is what you seek for :)
    $pupupu=array(...);
    foreach ($pupupu as $pupu):
    if($level=$pupu){
    blabla
    }
    endforeach;
    PHP:
     
    xenous, Nov 17, 2008 IP
  4. xenous

    xenous Peon

    Messages:
    102
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Bartloay33 just posted same at same time :) how ya doin m8?
     
    xenous, Nov 17, 2008 IP
  5. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #5
    So I think you want to check if the $level contains any one of the value in $pupupu

    
    $pupupu = array("admin","moderator");
    if(in_array($level,$pupupu) ) { 
    //blabla 
    }
    
    PHP:
     
    ads2help, Nov 17, 2008 IP
  6. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #6
    $pupupu = array(
       "admin" => true,
       "moderator" => true
    );
    if(isset($pupupu[$level]))
    {
    
    }
    Code (markup):
     
    joebert, Nov 18, 2008 IP
  7. osocash

    osocash Member

    Messages:
    49
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #7
    some great stuff, really helped my ;)
     
    osocash, Nov 18, 2008 IP