Noobi question , i know , but..

Discussion in 'PHP' started by Master_Moving, Mar 11, 2007.

  1. #1
    How im initialize array in php.
    If im doing foreach and set 0 on every member so the $key still exists..
    Thank u all , ur gr8 people! :D
     
    Master_Moving, Mar 11, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    
    $data = array
    (
    "Item 1",
    "Item 2"
    );
    
    $data = array
    (
    "Key_1" => "Item 1",
    "Key_2" => "Item 2"
    );
    
    $data["key_1"] = "Item 1";
    $data["key_2"] = "Item 2";
    
    
    PHP:
    Take your pick ......
     
    krakjoe, Mar 11, 2007 IP
  3. Master_Moving

    Master_Moving Guest

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks For the answer.
    no , its already an filled array and i want to initialize it with foreach ..
     
    Master_Moving, Mar 11, 2007 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    I dunno what you mean by 'initialize it with foreach', but foreach syntax works like :

    
    foreach( $array as $key => $value )
    {
      if($key == "whatever") echo "do the thing\n";
    }
    
    PHP:
     
    krakjoe, Mar 11, 2007 IP