By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

how to split the index and the value in the array

P: 65
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
May 16 '07 #1
Share this Question
Share on Google+
2 Replies


pbmods
Expert 5K+
P: 5,821
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:

Expand|Select|Wrap|Line Numbers
  1. //  keys and values
  2. foreach($array as $key => $val)
  3.     print("[$key] => $val<br />");
  4.  
  5. //  values only
  6. foreach($array as $val)
  7.     print("$val<br />");
  8.  
  9. // keys only
  10. foreach(array_keys($array) as $key)
  11.     print("$key<br />");
  12.  
  13. //  or...
  14. foreach($array as $key => $val)
  15.     print("$key<br />");
  16.  
For more information:
http://php.net/foreach
May 16 '07 #2

P: 65
thanks a lot..i have done it
May 16 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.