Ajay
Ajay

Reputation: 1117

getting values from a php array

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.

Upvotes: 0

Views: 112

Answers (2)

SIFE
SIFE

Reputation: 5695

You have two arrays, one inside another:

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

Upvotes: 0

heldt
heldt

Reputation: 4266

You have an array in an array. Try this

foreach ($tags_array['tags'] as $tag) {  
         echo $tag;           
       } 

Upvotes: 1

Related Questions