List posts of assigned categories in list of all categories on single.php

Solved it with following code. My idea posted above worked out, but I had to rearrange the assigned categories in a new array.

<ul>
<?php
    $cargs = array(
        'type'                     => 'post',
        'child_of'                 => 0,
        'parent'                   => '',
        'orderby'                  => 'name',
        'order'                    => 'ASC',
        'hide_empty'               => 0,
        'hierarchical'             => 1,
        'exclude'                  => '1',
        'include'                  => '',
        'number'                   => '',
        'taxonomy'                 => 'category',
        'pad_counts'               => false 

    ); 
    $categories = get_categories($cargs);
    $post = $wp_query->post;
    $postid = $post->ID;
    $postcategories = get_the_terms($postid, 'category');
    $postcategoriesids = array();
    foreach ($postcategories as $postcategory) {
        $postcategoriesids[] = $postcategory->term_id;
    };
    foreach($categories as $category) {
        if(in_array($category->term_id, $postcategoriesids)) {
            echo '<li class="currentcat"><a href="'.get_category_link($category->cat_ID).'" class="activelink">'.$category->cat_name."</a><ul>";
        }
        else {
            echo '<li class="zk_category-item"><a href="'.get_category_link($category->cat_ID).'">'.$category->cat_name."</a><ul>";
        }
        $category_posts=get_posts('category='.$category->cat_ID);
        foreach($category_posts as $post) {
            echo '<li class="zk_project-item"><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
        };
        echo "</ul></li>";
    };
?>