$test という変数をprint_r で見てみると、下記のようなときに、
Array ( [262] => WP_Post Object ( [ID] => 262 [post_author] => 1 [post_date] => 2016-11-25 15:29:03 [post_date_gmt] => 2016-11-25 06:29:03 [post_content] => [post_title] => slider1 [post_excerpt] => [post_status] => inherit [comment_status] => open ) [263] => WP_Post Object ( [ID] => 263 [post_author] => 1 [post_date] => 2016-11-25 15:29:03 [post_date_gmt] => 2016-11-25 06:29:03 [post_content] => [post_title] => vvv [post_excerpt] => [post_status] => inherit [comment_status] => open ) [264] => WP_Post Object ( [ID] => 264 [post_author] => 1 [post_date] => 2016-11-25 15:29:04 [post_date_gmt] => 2016-11-25 06:29:04 [post_content] => [post_title] => free-background36251 [post_excerpt] => [post_status] => inherit [comment_status] => open ) [265] => WP_Post Object ( [ID] => 265 [post_author] => 1 [post_date] => 2016-11-25 15:29:04 [post_date_gmt] => 2016-11-25 06:29:04 [post_content] => [post_title] => free-background36203 [post_excerpt] => [post_status] => inherit [comment_status] => open ) )
例えば、変数$test内の下にある階層の[post_title]だけのの個数をカウントしたい場合や、ループを使って[post_title]の中身を全て表示したいのですが、一番上の階層の配列名が異なるため、普通にcount()やforなどでループできないのですが、どのようにやるのがベストでしょうか?
[post_title]の中身を全て表示する、イメージとしては、
<?php for($x = 0; $x < count($text[][post_title]); $x++ ){ ?> <p><?php echo $text[][post_title][$x]; ?></p> <?php } ?>
このような感じで考えていたのですが、ちょっと無理が出てきてしまったので考え中です。よいやり方がありましたら、 教えてください。よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/25 09:27