문제

I'm modifying the WP JSON API core to return just the post titles from a query result object, rather than all the other data.

$posts = $json_api->introspector->get_posts($query);
$post_titles = array();
foreach ($posts as $post){
  $post_titles[] =  $post;          //result: {id:0, type:"post", title:"the title" ..}
  $post_titles[] =  $post['title']; //fail
}

When using gettype($posts) I get 'object', and I thought that $obj['key']; is how to get an object's property in PHP. Any help appreciated, thanks.

올바른 솔루션이 없습니다

다른 팁

Object properties are referenced with ->.

$post->title
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top