PHP如何检索数组值 [英] PHP how to retrieve array values
本文介绍了PHP如何检索数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下数组,我想检索 name
、comment
和 每个标签
(插入数据库.我怎样才能检索数组值.另外,我是否可以仅过滤大于 3 个字符且仅包含 a-Z0-9 值的标签值.非常感谢.
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
)
)
)
推荐答案
$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
}
或单独访问每个
echo $tags[0];
echo $tags[1];
这篇关于PHP如何检索数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文