how to split the index and the value in the array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wish
    New Member
    • May 2007
    • 65

    #1

    how to split the index and the value in the array

    Hello
    My problem is when print out the array, it will include the index of the array and then value like this [0] => haha...
    if i just want the value print out like "haha" only then what should i write?
    Can some one guide me?Thank
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    print_r always outputs keys and values, since it is designed for debugging.

    You can use a foreach loop to traverse through an array, though:

    [code=php]
    // keys and values
    foreach($array as $key => $val)
    print("[$key] => $val<br />");

    // values only
    foreach($array as $val)
    print("$val<br />");

    // keys only
    foreach(array_k eys($array) as $key)
    print("$key<br />");

    // or...
    foreach($array as $key => $val)
    print("$key<br />");
    [/code]

    For more information:

    Comment

    • wish
      New Member
      • May 2007
      • 65

      #3
      thanks a lot..i have done it

      Comment

      Working...