php大神解答下

來源:互聯網
上載者:User
關鍵字 php
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;}

遞迴迴圈讀取

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.