php大神解答下
程序员文章站
2022-05-25 19:28:53
...
Array ( [0] => WP_Post Object ( [ID] => 39 [post_author] => 1 [post_date] => 2016-04-03 21:59:44 [post_date_gmt] => 2016-04-03 13:59:44 [post_content] => 11111 [post_title] => 测试3 [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => %e6%b5%8b%e8%af%953 [to_ping] => [pinged] => [post_modified] => 2016-04-03 21:59:44 [post_modified_gmt] => 2016-04-03 13:59:44 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/wordpress/?p=39 [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw ) [1] => WP_Post Object ( [ID] => 37 [post_author] => 1 [post_date] => 2016-04-03 17:02:16 [post_date_gmt] => 2016-04-03 09:02:16 [post_content] => 测试2 [post_title] => 测试2 [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => %e6%b5%8b%e8%af%952 [to_ping] => [pinged] => [post_modified] => 2016-04-03 17:02:16 [post_modified_gmt] => 2016-04-03 09:02:16 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/wordpress/?p=37 [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw ) [2] => WP_Post Object ( [ID] => 35 [post_author] => 1 [post_date] => 2016-04-03 16:50:04 [post_date_gmt] => 2016-04-03 08:50:04 [post_content] => 测试文章1 [post_title] => 测试文章 [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => %e6%b5%8b%e8%af%95%e6%96%87%e7%ab%a0 [to_ping] => [pinged] => [post_modified] => 2016-04-03 16:50:04 [post_modified_gmt] => 2016-04-03 08:50:04 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/wordpress/?p=35 [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw ) )
这样的数组 怎么用循环取到里面的值 比如取里面的 post_title
回复内容:
Array ( [0] => WP_Post Object ( [ID] => 39 [post_author] => 1 [post_date] => 2016-04-03 21:59:44 [post_date_gmt] => 2016-04-03 13:59:44 [post_content] => 11111 [post_title] => 测试3 [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => %e6%b5%8b%e8%af%953 [to_ping] => [pinged] => [post_modified] => 2016-04-03 21:59:44 [post_modified_gmt] => 2016-04-03 13:59:44 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/wordpress/?p=39 [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw ) [1] => WP_Post Object ( [ID] => 37 [post_author] => 1 [post_date] => 2016-04-03 17:02:16 [post_date_gmt] => 2016-04-03 09:02:16 [post_content] => 测试2 [post_title] => 测试2 [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => %e6%b5%8b%e8%af%952 [to_ping] => [pinged] => [post_modified] => 2016-04-03 17:02:16 [post_modified_gmt] => 2016-04-03 09:02:16 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/wordpress/?p=37 [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw ) [2] => WP_Post Object ( [ID] => 35 [post_author] => 1 [post_date] => 2016-04-03 16:50:04 [post_date_gmt] => 2016-04-03 08:50:04 [post_content] => 测试文章1 [post_title] => 测试文章 [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => %e6%b5%8b%e8%af%95%e6%96%87%e7%ab%a0 [to_ping] => [pinged] => [post_modified] => 2016-04-03 16:50:04 [post_modified_gmt] => 2016-04-03 08:50:04 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/wordpress/?p=35 [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw ) )
这样的数组 怎么用循环取到里面的值 比如取里面的 post_title
这是一个含有三个WP_Post Object对象元素的数组,获取元素对象后,再获取其属性即可,代码如下:
foreach($array as $key => $value){
if($value->post_title)
echo $value->post_title;
}
递归循环读取
上一篇: 怎样利用JS实现动态进度条
推荐阅读
-
详解Centos下YUM安装PHP的两种方式
-
Ubuntu 14.04 下开启PHP错误提示
-
Windows下Nginx + PHP5 的安装与配置方法
-
Windows下Nginx+PHP5的安装与配置方法
-
分享下PHP register_globals 值为on与off的理解
-
php web环境和命令行环境下查找php.ini的位置
-
PHP用mb_string函数库处理与windows相关中文字符及Win环境下开启PHP Mb_String方法
-
CentOS 6.3下给PHP添加mssql扩展模块教程
-
PHP下打开phpMyAdmin出现403错误的问题解决方法
-
浅析Dos下运行php.exe,出现没有找到php_mbstring.dll 错误的解决方法