How to calculate posts number?

I want to achieve something like this:

foreach ( $posts as $post ) {
    if ( $a = $b ) ) {
        // if true +1 to the result;
    } else {
        // if not true -2 to the result;
    }
}

echo 'Your result is X';

How to replace X with the result of a calculation? How calculation code should look?

Topic count Wordpress

Category Web


Do you mean like this

$result = 10;

foreach ( $posts as $post ) {
    if ( $a = $b ) ) {
        $result += 1;
    } else {
        $result -= 2;
    }
}

echo 'Your result is ' . $result;

This is the best I can do with the provided information

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.