0

I want to get values from an array, For example this is array:

$tags_array = $_REQUEST['item'];

With print_r, I get following:

Array
(
    [tags] => Array
        (
            [0] => tag1
            [1] => tag2
        )

)

I want to get values of array with for each loop.

foreach ($tags_array as $tag) {  
         echo $tag;           
       } 

It prints nothing. Thanks for help.

2
  • It should at least print Array or something like that... Commented Apr 10, 2011 at 0:04
  • I'm gonna take a guess here and think $tag actually holds this type of information: <tag>. If you echo that in a browser it will interpret it as an actual html tag, and thereby showing nothing. Look at the html code in your browser, or do a print_r( $tag ) Commented Apr 10, 2011 at 0:04

2 Answers 2

1

You have an array in an array. Try this

foreach ($tags_array['tags'] as $tag) {  
         echo $tag;           
       } 
Sign up to request clarification or add additional context in comments.

Comments

0

You have two arrays, one inside another:

foreach ($tags_array as $tag_array) {  
         foreach ($tag_array as $tag)          
              echo $tag;
       } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.