首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP:我怎样才能得到“你好世界!”在$variable中从这个数组中退出?

PHP:我怎样才能得到“你好世界!”在$variable中从这个数组中退出?
EN

Stack Overflow用户
提问于 2016-12-28 15:09:02
回答 3查看 53关注 0票数 0

我的排列有点问题,我希望有人能在这里帮我:

代码语言:javascript
复制
Array ( 
[0] => Pagekit\Blog\Model\Post Object ( 
    [id] => x 
    [title] => x 
    [slug] => x
    [user_id] => x 
    [date] => DateTime Object ( 
        [date] => 2016-12-28 07:51:02.000000 
        [timezone_type] => 3 
        [timezone] => UTC 
    ) 
    [content] => xxxxxxxxxxxx
    [excerpt] => xxxxxxxxxxxx
    [status] => xxxxxxxxxxxx 
    [modified] => DateTime Object ( 
        [date] => 2016-12-28 09:17:48.000000 
        [timezone_type] => 3 
        [timezone] => UTC 
    ) 
    [comment_status] => 1 
    [comment_count] => 0 
    [user] => Pagekit\User\Model\User Object ( 
        [id] => 1 
        [username] => xxxxxxxxxxxx 
        [password] => xxxxxxxxxxxx 
        [email] => xxxxxxxxxxxx 
        [url] => xxxxxxxxxxxx
        [registered] => DateTime Object ( 
            [date] => 2016-12-15 15:33:36.000000 
            [timezone_type] => 3 
            [timezone] => UTC 
        ) 
        [status] => 1 
        [name] => xxxxxxxxxxxx 
        [login] => DateTime Object ( 
            [date] => 2016-12-27 13:55:45.000000 
            [timezone_type] => 3 
            [timezone] => UTC 
        ) 
        [activation] => [permissions:protected] => [roles] => Array ( 
            [0] => x 
            [1] => x 
        ) 
        [data] => Array ( 
            [admin] => Array ( 
                [menu] => Array ( 
                    [dashboard] => x 
                    [user] => x 
                    [system: system] => x 
                    [blog] => x
                    [system: marketplace] => x
                    [portfolio] => x
                    [site] => x
                ) 
            ) 
        ) 
    ) 
    [comments] => [roles] => Array ( ) 
    [data] => Array ( 
        [title] => [markdown] => 1 [image] => Array ( 
            [src] => storage/bilderbuch/bild.jpg 
            [alt] => bild 
        ) 
        [meta] => Array ( 
            [og:description] => Hello World! 
        ) 
    ) 
)   
)

有人能解释一下我如何从这里得到Hello World!或其他所有东西吗?(这个大数组中的最后一行)

代码语言:javascript
复制
[meta] => Array ( 
            [og:description] => Hello World!

$Variable里?我知道这可能是个愚蠢的问题,但我只在一个星期或什么时候使用PHP。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-12-28 15:13:48

您的$variable是一个数组,其中包含一个项。

这个项目是一个Pagekit\Blog\Model\Post对象,所以首先需要$variable[0]才能到达那里。

注意-这个对象有几个属性,您正在寻找data属性:$variable[0]->data

这个属性本身就是一个array,其中meta是它的键$variable[0]->data['meta']之一,它是另一个带有og:description键的数组。

所以你需要的最后一个变量是

代码语言:javascript
复制
$variable[0]->data['meta']['og:description']
票数 2
EN

Stack Overflow用户

发布于 2016-12-28 15:13:40

我相信你用过https://pagekit.com/docs/developer/orm

在这种情况下,可以迭代结果并返回元数据:

代码语言:javascript
复制
$meta = [];
foreach ($array as $post)
{
    $meta[] = $post->data['meta'];
}
var_dump($meta);
票数 1
EN

Stack Overflow用户

发布于 2016-12-28 15:32:01

所以解决办法是:

代码语言:javascript
复制
$test = spliting($posts, 3);
$var1 = $test[0]->data['meta']['og:description'];

在这里,分裂函数只将整个数组分成3部分。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41364719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档