gpt4 book ai didi

php - 如何将对象转换为数组以获取数据?

转载 作者:可可西里 更新时间:2023-11-01 13:51:30 24 4
gpt4 key购买 nike

我的数组是这样的

Array ( [0] => stdClass Object ( [ID] => 578 [post_author] => 1 [post_date] => 2011-01-18 07:23:17 [post_date_gmt] => 2011-01-18 07:23:17 [post_content] => Home WordPress is web software you can use to create a beautiful website or blog. We like to say that WordPress is both free and priceless at the same time. The core software is built by hundreds of community volunteers, and when you’re ready for more there are thousands of plugins and themes available to transform your site into almost anything you can imagine. Over 25 million people have chosen WordPress to power the place on the web they call “home” — we’d love you to join the family [post_title] => second post [post_excerpt] => [post_status] => publish [comment_status] => open

当我这样写的时候

$myposts = get_posts( $args );
$arrDt = (array) $myposts;
print_r($arrDt);

但我的问题是如何获取该对象数组中的值。

请帮忙。谢谢print_r($arrDt);

最佳答案

这只是普通的对象访问:

$obj = $arrDt[0];
echo $obj->ID;
echo $obj->post_author;
// etc.

但这取决于你想做什么。我建议看看 get_posts例子。他们使用 setup_postdata 在当前上下文中加载帖子内容。如果您想显示帖子,这可能是更简洁的解决方案。

关于php - 如何将对象转换为数组以获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4767589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com