Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Count the number of substring occurrences
substr_count(    string $haystack,    string $needle,    int $offset 0,    ?int $length null): int
    public static function substrCount($haystack$needle$offset 0$length null)

    {

        if (! 
is_null($length)) {

            return 
substr_count($haystack$needle$offset$length);

        } else {

            return 
substr_count($haystack$needle$offset);

        }
        if (! is_null($length)) {

            return 
substr_count($haystack$needle$offset$length);

        } else {

            return 
substr_count($haystack$needle$offset);

        }

    }
        $query EloquentTestUser::has('postWithPhotos');



        
$bindingsCount count($query->getBindings());

        
$questionMarksCount substr_count($query->toSql(), '?');



        
$this->assertEquals($questionMarksCount$bindingsCount);

    }