Php数组返回无意义值

时间:2018-01-13 16:29:47

标签: php arrays wordpress

我有一个数组:

//$post array values
Array (
[0] => WP_Post Object ( [ID] => 580 [post_author] => 1 [post_date] => 2017-10-30 15:30:49 [post_date_gmt] => 2017-10-30 14:30:49 [post_content] => [post_title] => 2017-10-30, hétfő [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => 2017-10-30-hetfo [to_ping] => [pinged] => [post_modified] => 2018-01-13 16:05:46 [post_modified_gmt] => 2018-01-13 15:05:46 [post_content_filtered] => [post_parent] => 0 [guid] => http://vegachef.hu/?post_type=etlap&p=580 [menu_order] => 0 [post_type] => etlap [post_mime_type] => [comment_count] => 0 [filter] => raw )
[1] => WP_Post Object ( [ID] => 581 [post_author] => 1 [post_date] => 2017-10-30 15:42:13 [post_date_gmt] => 2017-10-30 14:42:13 [post_content] => [post_title] => 2017-10-31, kedd [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => 2017-10-31-kedd [to_ping] => [pinged] => [post_modified] => 2017-12-26 00:39:41 [post_modified_gmt] => 2017-12-25 23:39:41 [post_content_filtered] => [post_parent] => 0 [guid] => http://vegachef.hu/?post_type=etlap&p=581 [menu_order] => 0 [post_type] => etlap [post_mime_type] => [comment_count] => 0 [filter] => raw )
[2] => WP_Post Object ( [ID] => 762 [post_author] => 4 [post_date] => 2017-12-20 17:48:35 [post_date_gmt] => 2017-12-20 16:48:35 [post_content] => [post_title] => 2017-11-01, szerda [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => 2017-11-01-szerda [to_ping] => [pinged] => [post_modified] => 2018-01-12 01:56:27 [post_modified_gmt] => 2018-01-12 00:56:27 [post_content_filtered] => [post_parent] => 0 [guid] => http://vegachef.hu/?post_type=etlap&p=762 [menu_order] => 0 [post_type] => etlap [post_mime_type] => [comment_count] => 0 [filter] => raw )
[3] => WP_Post Object ( [ID] => 763 [post_author] => 4 [post_date] => 2017-12-20 17:48:59 [post_date_gmt] => 2017-12-20 16:48:59 [post_content] => [post_title] => 2017-11-02, csütörtök [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => 2017-11-02-csutortok [to_ping] => [pinged] => [post_modified] => 2017-12-27 00:21:16 [post_modified_gmt] => 2017-12-26 23:21:16 [post_content_filtered] => [post_parent] => 0 [guid] => http://vegachef.hu/?post_type=etlap&p=763 [menu_order] => 0 [post_type] => etlap [post_mime_type] => [comment_count] => 0 [filter] => raw )
[4] => WP_Post Object ( [ID] => 764 [post_author] => 4 [post_date] => 2017-12-20 17:49:18 [post_date_gmt] => 2017-12-20 16:49:18 [post_content] => [post_title] => 2017-11-03, péntek [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => 2017-11-03-pentek [to_ping] => [pinged] => [post_modified] => 2018-01-10 01:00:06 [post_modified_gmt] => 2018-01-10 00:00:06 [post_content_filtered] => [post_parent] => 0 [guid] => http://vegachef.hu/?post_type=etlap&p=764 [menu_order] => 0 [post_type] => etlap [post_mime_type] => [comment_count] => 0 [filter] => raw ) )

我还有一张桌子,我需要在<thead> <tr> <td>

中写下每个post_title

我做了一个foreach循环,但它返回了有趣的值:

return values

我不知道为什么,因为我的foreach()循环对我来说似乎没问题:

<thead class="first-row-thead">
    <tr>
        <td id="fist-value-td">
        </td>
   <?php foreach ($post as $post_title => $get_title): ?>
       <td class="dates-container-td">
           <div class="dates-container-div">
               <h1 class="dates-h1"><?php echo $get_title['post_title']; ?></h1>
           </div>
       </td>
    <?php endforeach; ?>

3 个答案:

答案 0 :(得分:1)

您的数组似乎是一个对象,而不是一个数组。对于您需要使用的对象:

$get_title->post_title

编辑:代码输出更好

答案 1 :(得分:0)

您遗失[post_content] => "value"
这可能导致您的错误..重新检查数组中的关联值

答案 2 :(得分:0)

尝试以下内容,在foreach中进行更改 -

                                         帖子标题; ?&GT;