Passing variable from filter

Try to define $count4footer outside the function wpa_filter_nav_menu_objects.

$count4footer = array( );

function wpa_filter_nav_menu_objects( $items){
    global $count4footer;

    foreach( $items as $item ){

        $count = countPosts($item->ID);
        if($count!==false){
            $item->title = $item->title." ($count)";
            $count4footer[$item->ID]=$count;
        }
    }

    return $items;
}

add_filter( 'wp_nav_menu_objects', 'wpa_filter_nav_menu_objects' );

tech