A code that I could not fully grasp related to foreach & count_user_posts()

Those parameters are optional, as the codex states:

$post_type

(string) (optional) Post type to count the number of posts for.

    Default: "post"

So it’s optional, not required. If it isn’t passed in, then the default value is "post".

Optional parameters are a part of PHP, e.g.


function print_number( $number=5 ) {
    echo $number;
}
print_number( 2 ); // prints 2
print_number(); // prints 5

Note that this doesn’t mean all parameters are optional. Check the parameter in the docs for the function you’re using to see if it’s optional, and what its default is