PHP如何遍历WP对象
我对PHP真的很陌生。从我所学到的/读到的。要在php中迭代对象,请使用PHP如何遍历WP对象,php,arrays,wordpress,Php,Arrays,Wordpress,我对PHP真的很陌生。从我所学到的/读到的。要在php中迭代对象,请使用->;要迭代数组,请使用[“itemInArray”]。这听起来可能很愚蠢,但我如何从下面的对象中获取一些东西呢?比如说,post\u内容 我已经在一个通过多维数组循环的foreach循环中。这看起来像: foreach ($key as $b=>$test) { var_dump($test["post_content"]); } - 我的目标: object(WP_Post)#7239 (24) { ["I
->
;要迭代数组,请使用[“itemInArray”]
。这听起来可能很愚蠢,但我如何从下面的对象中获取一些东西呢?比如说,post\u内容
我已经在一个通过多维数组循环的foreach
循环中。这看起来像:
foreach ($key as $b=>$test) {
var_dump($test["post_content"]);
}
-
我的目标:
object(WP_Post)#7239 (24) {
["ID"]=>
int(2127)
["post_author"]=>
string(1) "5"
["post_date"]=>
string(19) "2016-04-29 09:45:55"
["post_date_gmt"]=>
string(19) "2016-04-29 09:45:55"
["post_content"]=>
string(313) "<p class="p1"><span class="s1">Some dummy content</span></p>
<p class="p1"><em>Support from whateves</em></p>"
["post_title"]=>
string(12) "The Title"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(12) "the-title"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2016-11-24 14:34:01"
["post_modified_gmt"]=>
string(19) "2016-11-24 14:34:01"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(66) "http://www.localhost:8080/?post_type=creator&p=2127"
["menu_order"]=>
int(0)
["post_type"]=>
string(17) "creator"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
对象(WP#u Post)#7239(24){
[“ID”]=>
国际(2127)
[“post_author”]=>
字符串(1)“5”
[“发布日期”]=>
字符串(19)“2016-04-29 09:45:55”
[“发布日期\u gmt”]=>
字符串(19)“2016-04-29 09:45:55”
[“发布内容”]=>
字符串(313)“一些虚拟内容
来自whateves的支持
[“帖子标题”]=>
字符串(12)“标题”
[“post_摘录”]=>
字符串(0)”
[“发布状态”]=>
字符串(7)“发布”
[“评论状态”]=>
字符串(6)“已关闭”
[“ping_状态”]=>
字符串(6)“已关闭”
[“发布密码”]=>
字符串(0)”
[“职位名称”]=>
字符串(12)“标题”
[“to_ping”]=>
字符串(0)”
[“ping”]=>
字符串(0)”
[“修改后”]=>
字符串(19)“2016-11-2414:34:01”
[“修改后的gmt”]=>
字符串(19)“2016-11-2414:34:01”
[“内容过滤后”]=>
字符串(0)”
[“后家长”]=>
int(0)
[“guid”]=>
字符串(66)”http://www.localhost:8080/?post_type=creator&;p=2127“
[“菜单顺序”]=>
int(0)
[“post_type”]=>
字符串(17)“创建者”
[“post\u mime\u type”]=>
字符串(0)”
[“评论计数”]=>
字符串(1)“0”
[“过滤器”]=>
字符串(3)“原始”
}
这应该可以做到
echo$test->post\u内容代码>
PHP数组和对象之间的区别如下:
数组:
$array = new Array();
$array['test'] = 'test';
echo $array['test'];
对象:
$object = new stdClass();
$object->test = 'test';
echo $object->test;
这应该能奏效
echo$test->post\u内容代码>
PHP数组和对象之间的区别如下:
数组:
$array = new Array();
$array['test'] = 'test';
echo $array['test'];
对象:
$object = new stdClass();
$object->test = 'test';
echo $object->test;