Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP how to retrieve array values

Tags:

arrays

php

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
                )

        )

)
like image 706
Ajay Avatar asked Feb 25 '23 14:02

Ajay


2 Answers

$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];
like image 81
RDL Avatar answered Mar 08 '23 12:03

RDL


$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

like image 43
Rocket Hazmat Avatar answered Mar 08 '23 13:03

Rocket Hazmat