Looping through Object ActiveRecord?

Hello!

My query looks like this:


 $category = Category::find()->select('post.id_post, post.content ,category.id_category')

            ->innerJoinWith('posts')->orderBy('post.id_post')

            ->all();

My query return


	SELECT `category`.`id_category`, `post`.`id_post`, `post`.`content` FROM `category` INNER JOIN `post` ON `category`.`id_category` = `post`.`id_categoryFK` ORDER BY `post`.`id_post`

How i can write in loop foreach all records ? I would like to get result such as below

all() method returns array of objects (or empty array).

So you can simply use:




foreach ($category as $cat)

{

    echo $cat->id_category;

}



Or, probably:




foreach ($category as $cat) {

    foreach ($cat->posts as $post) {

        echo $cat->id_category;

        echo $post->id_post;

        echo $post->content;

    }

}



Great mate!! I tried through one loop foreach and I lost index :)