Echo在PHP数组的值 [英] Echo the values of an array in PHP

查看:80
本文介绍了Echo在PHP数组的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何呼应例如下面的数组的标题? (项)。使用的print_r我得到这个(我只张贴它的一部分)。
我想创造我想呼应的每个项目的变量,这将帮助我在显示结果之前,做一些关于它的修改。

感谢您的StackOverflow!

 阵列

    [0] => SimpleXMLElement对象
        (
            [GUID] =>标签:blogger.com,1999:博客 - 8508477708802179245.post-7592005355313594438
            [pubdate的] =>太阳,2011 12:05:00 +0000 5月29日
            【类别】= GT;思考
            [标题] =>我应该去吗?




解决方案

  

我如何呼应例如下面的数组的标题?


下标第一个数组元素,然后访问它的标题属性...

 回声$项[0]  - >称号;


  

我要创造我想每个项目一个变量回声


您可以手动执行此操作...

  $标题= $条目[0]  - >称号;

,使用自动完成提取物() ...

 提取物((阵列)$项[0],EXTR_SKIP);

要小心提取物()。它不会覆盖与 EXTR_SKIP 标志现有的变量,所以记住这一点。

How can I echo for example the title of the following array? (entries). Using print_r I get this ( I post only a part of it). I would like to create a variable for each item I want to echo, this will help me on doing some modifications on it before showing the result.

Thank you stackoverflow!

Array
(
    [0] => SimpleXMLElement Object
        (
            [guid] => tag:blogger.com,1999:blog-8508477708802179245.post-7592005355313594438
            [pubDate] => Sun, 29 May 2011 12:05:00 +0000
            [category] => Thoughts
            [title] => Should I go for it ?
.
.
.

解决方案

How can I echo for example the title of the following array?

Subscript the first array element, and then access its title property...

echo $entries[0]->title;

I would like to create a variable for each item I want to echo

You could do this manually...

$title = $entries[0]->title;

Or do it automatically with extract()...

extract((array) $entries[0], EXTR_SKIP);

Be careful with extract(). It won't overwrite existing variables with the EXTR_SKIP flag, so keep that in mind.

这篇关于Echo在PHP数组的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆