PHP:如何从 $variable 中的数组中取出 "Hello World!"?

PHP: How can I get the "Hello World!" out of this array in a $variable?

我的阵列有点问题,希望有人能帮助我:

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! 或其他所有内容吗:(这个大数组的最后几行)

[meta] => Array ( 
            [og:description] => Hello World!

$Variable?我知道这可能是一个愚蠢的问题,但我使用 PHP 才一周左右。

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

在您的情况下,您可以遍历结果和 return 元数据:

$meta = [];
foreach ($array as $post)
{
    $meta[] = $post->data['meta'];
}
var_dump($meta);

您的 $variable 是一个包含 1 项的数组。
此项目是一个 Pagekit\Blog\Model\Post 对象,因此首先您需要 $variable[0] 才能到达那里。

注意 - 此对象有多个属性,您正在查找 data 属性:$variable[0]->data.

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

所以你需要的最终变量实际上是

$variable[0]->data['meta']['og:description']

所以解决方案是:

$test = spliting($posts, 3);
$var1 = $test[0]->data['meta']['og:description'];

这里的拆分函数只是把整个数组分成3份