4

I have following array, I want to retrieve name, comment and each of the tags (to insert in database. How can i retrieve the array values. Also, can i filter ONLY the tags values which are larger than 3 characters and contains only a-Z0-9 valueus. Thank you very much.

Array
(
    [folder] => /test
    [name] => ajay
    [comment] => hello world.. test comment
    [item] => Array
        (
            [tags] => Array
                (
                    [0] => javascript
                    [1] => coldfusion
                )

        )

)
2
  • See PHP manual on how to access array values. Filtering may be done via regex Commented Apr 6, 2011 at 15:32
  • You should view my questions i've asked a load about this topic and how different circumstances it can be used. Commented Apr 6, 2011 at 15:34

3 Answers 3

7
$name = $array['name'];
$comment = $array['comment'];
$tags = $array['item']['tags']; // this will be an array of the tags

You can then loop over the tags like:

foreach ($tags as $tag) {
  // do something with tag
}

Or access each one individually

echo $tags[0];
echo $tags[1];
Sign up to request clarification or add additional context in comments.

Comments

2
$name = $array['name'];
echo $name; // ajay

$comment = $array['comment']
echo $comment;  //hello world.. test comment

$tags = $array['item']['tags'];
echo $tags[0]; // javascript
echo $tags[1]; // coldfusion

http://www.php.net/manual/en/language.types.array.php

Comments

1

To filter tags longer than 3 chars and only tags contain a-z, A-Z, 0-9 you can use this code

$alltags =  $your_array["item"]["tags"];

$valid_tags = array();
foreach($alltags as $tag)
  if ((preg_match("/^[a-zA-Z0-9]+$/", $tag) == 1) && (strlen($tag) > 3)) $valid_tags[] = $tag;

Use it like

print_r($valid_tags);

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.